Merge branch '1.0.0' into #133
This commit is contained in:
commit
b9d33c5fd0
@ -25,10 +25,10 @@ class ModuleList:
|
|||||||
DataModule,
|
DataModule,
|
||||||
GraphQLModule,
|
GraphQLModule,
|
||||||
PermissionModule,
|
PermissionModule,
|
||||||
|
LevelModule,
|
||||||
DatabaseModule,
|
DatabaseModule,
|
||||||
AutoRoleModule,
|
AutoRoleModule,
|
||||||
BaseModule,
|
BaseModule,
|
||||||
LevelModule,
|
|
||||||
ApiModule,
|
ApiModule,
|
||||||
TechnicianModule,
|
TechnicianModule,
|
||||||
# has to be last!
|
# has to be last!
|
||||||
|
@ -69,11 +69,11 @@ class ApiKey(TableABC):
|
|||||||
return str(
|
return str(
|
||||||
f"""
|
f"""
|
||||||
INSERT INTO `ApiKeys` (
|
INSERT INTO `ApiKeys` (
|
||||||
`Identifier`, `Key`, `CreatorId`, `CreatedAt`, `LastModifiedAt`
|
`Identifier`, `Key`, {"" if self._creator is None else "`CreatorId`,"} `CreatedAt`, `LastModifiedAt`
|
||||||
) VALUES (
|
) VALUES (
|
||||||
'{self._identifier}',
|
'{self._identifier}',
|
||||||
'{self._key}',
|
'{self._key}',
|
||||||
{"NULL" if self._creator is None else self._creator.id},
|
{"" if self._creator is None else f"{self._creator.id},"}
|
||||||
'{self._created_at}',
|
'{self._created_at}',
|
||||||
'{self._modified_at}'
|
'{self._modified_at}'
|
||||||
);
|
);
|
||||||
@ -87,6 +87,7 @@ class ApiKey(TableABC):
|
|||||||
UPDATE `ApiKeys`
|
UPDATE `ApiKeys`
|
||||||
SET `Identifier` = '{self._identifier}',
|
SET `Identifier` = '{self._identifier}',
|
||||||
`Key` = '{self._key}',
|
`Key` = '{self._key}',
|
||||||
|
{"" if self._creator is None else f"`CreatorId` = {self._creator.id},"}
|
||||||
`LastModifiedAt` = '{self._modified_at}'
|
`LastModifiedAt` = '{self._modified_at}'
|
||||||
WHERE `Id` = {self._id};
|
WHERE `Id` = {self._id};
|
||||||
"""
|
"""
|
||||||
|
@ -215,10 +215,10 @@ class AuthUser(TableABC):
|
|||||||
`EMail`,
|
`EMail`,
|
||||||
`Password`,
|
`Password`,
|
||||||
`PasswordSalt`,
|
`PasswordSalt`,
|
||||||
`RefreshToken`,
|
{"" if self._refresh_token is None else f"`RefreshToken`,"}
|
||||||
`ConfirmationId`,
|
{"" if self._confirmation_id is None else f"`ConfirmationId`,"}
|
||||||
`ForgotPasswordId`,
|
{"" if self._forgot_password_id is None else f"`ForgotPasswordId`,"}
|
||||||
`OAuthId`,
|
{"" if self._oauth_id is None else f"`OAuthId`,"}
|
||||||
`RefreshTokenExpiryTime`,
|
`RefreshTokenExpiryTime`,
|
||||||
`AuthRole`,
|
`AuthRole`,
|
||||||
`CreatedAt`,
|
`CreatedAt`,
|
||||||
@ -230,10 +230,10 @@ class AuthUser(TableABC):
|
|||||||
'{self._email}',
|
'{self._email}',
|
||||||
'{self._password}',
|
'{self._password}',
|
||||||
'{self._password_salt}',
|
'{self._password_salt}',
|
||||||
'{"NULL" if self._refresh_token is None else self._refresh_token}',
|
{"" if self._refresh_token is None else f"'{self._refresh_token}',"}
|
||||||
'{"NULL" if self._confirmation_id is None else self._confirmation_id}',
|
{"" if self._confirmation_id is None else f"'{self._confirmation_id}',"}
|
||||||
'{"NULL" if self._forgot_password_id is None else self._forgot_password_id}',
|
{"" if self._forgot_password_id is None else f"'{self._forgot_password_id}',"}
|
||||||
'{"NULL" if self._oauth_id is None else self._oauth_id}',
|
{"" if self._oauth_id is None else f"'{self._oauth_id}',"}
|
||||||
'{self._refresh_token_expire_time.isoformat()}',
|
'{self._refresh_token_expire_time.isoformat()}',
|
||||||
{self._auth_role_id.value},
|
{self._auth_role_id.value},
|
||||||
'{self._created_at}',
|
'{self._created_at}',
|
||||||
@ -252,10 +252,10 @@ class AuthUser(TableABC):
|
|||||||
`EMail` = '{self._email}',
|
`EMail` = '{self._email}',
|
||||||
`Password` = '{self._password}',
|
`Password` = '{self._password}',
|
||||||
`PasswordSalt` = '{self._password_salt}',
|
`PasswordSalt` = '{self._password_salt}',
|
||||||
`RefreshToken` = '{'null' if self._refresh_token is None else f'{self._refresh_token}'}',
|
{'' if self._refresh_token is None else f"`RefreshToken` = '{self._refresh_token}',"}
|
||||||
`ConfirmationId` = '{'null' if self._confirmation_id is None else f'{self._confirmation_id}'}',
|
{'' if self._confirmation_id is None else f"'`ConfirmationId` = '{self._confirmation_id}',"}
|
||||||
`ForgotPasswordId` = '{'null' if self._forgot_password_id is None else f'{self._forgot_password_id}'}',
|
{'' if self._forgot_password_id is None else f"`ForgotPasswordId` = '{self._forgot_password_id}',"}
|
||||||
`OAuthId` = '{'null' if self._oauth_id is None else f'{self._oauth_id}'}',
|
{'' if self._oauth_id is None else f"`OAuthId` = '{self._oauth_id}',"}
|
||||||
`RefreshTokenExpiryTime` = '{self._refresh_token_expire_time.isoformat()}',
|
`RefreshTokenExpiryTime` = '{self._refresh_token_expire_time.isoformat()}',
|
||||||
`AuthRole` = {self._auth_role_id.value},
|
`AuthRole` = {self._auth_role_id.value},
|
||||||
`LastModifiedAt` = '{self._modified_at}'
|
`LastModifiedAt` = '{self._modified_at}'
|
||||||
|
@ -150,11 +150,11 @@ class User(TableABC):
|
|||||||
return str(
|
return str(
|
||||||
f"""
|
f"""
|
||||||
INSERT INTO `Users` (
|
INSERT INTO `Users` (
|
||||||
`DiscordId`, `XP`, `MinecraftId`, `ServerId`, `CreatedAt`, `LastModifiedAt`
|
`DiscordId`, `XP`, {"" if self._minecraft_id is None else "`MinecraftId`,"} `ServerId`, `CreatedAt`, `LastModifiedAt`
|
||||||
) VALUES (
|
) VALUES (
|
||||||
{self._discord_id},
|
{self._discord_id},
|
||||||
{self._xp},
|
{self._xp},
|
||||||
'{self._minecraft_id}',
|
{"" if self._minecraft_id is None else f"'{self._minecraft_id}',"}
|
||||||
{self._server.id},
|
{self._server.id},
|
||||||
'{self._created_at}',
|
'{self._created_at}',
|
||||||
'{self._modified_at}'
|
'{self._modified_at}'
|
||||||
@ -168,7 +168,7 @@ class User(TableABC):
|
|||||||
f"""
|
f"""
|
||||||
UPDATE `Users`
|
UPDATE `Users`
|
||||||
SET `XP` = {self._xp},
|
SET `XP` = {self._xp},
|
||||||
`MinecraftId` = {'null' if self.minecraft_id is None else f'{self._minecraft_id}'},
|
{"" if self._minecraft_id is None else f"`MinecraftId` = '{self._minecraft_id}',"}
|
||||||
`LastModifiedAt` = '{self._modified_at}'
|
`LastModifiedAt` = '{self._modified_at}'
|
||||||
WHERE `UserId` = {self._user_id};
|
WHERE `UserId` = {self._user_id};
|
||||||
"""
|
"""
|
||||||
|
@ -98,30 +98,15 @@ class UserJoinedGameServer(TableABC):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def insert_string(self) -> str:
|
def insert_string(self) -> str:
|
||||||
if self._leaved_on is not None:
|
|
||||||
return str(
|
return str(
|
||||||
f"""
|
f"""
|
||||||
INSERT INTO `UserJoinedGameServer` (
|
INSERT INTO `UserJoinedGameServer` (
|
||||||
`UserId`, `GameServer`, `JoinedOn`, `LeavedOn`, `CreatedAt`, `LastModifiedAt`
|
`UserId`, `GameServer`, `JoinedOn`, {"" if self._leaved_on is None else "`LeavedOn`,"} `CreatedAt`, `LastModifiedAt`
|
||||||
) VALUES (
|
|
||||||
{self._user.id},
|
|
||||||
'{self._game_server}',
|
|
||||||
'{self._joined_on}',
|
|
||||||
'{self._leaved_on}',
|
|
||||||
'{self._created_at}',
|
|
||||||
'{self._modified_at}'
|
|
||||||
);
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
return str(
|
|
||||||
f"""
|
|
||||||
INSERT INTO `UserJoinedGameServer` (
|
|
||||||
`UserId`, `GameServer`, `JoinedOn`, `CreatedAt`, `LastModifiedAt`
|
|
||||||
) VALUES (
|
) VALUES (
|
||||||
{self._user.id},
|
{self._user.id},
|
||||||
'{self._game_server}',
|
'{self._game_server}',
|
||||||
'{self._joined_on}',
|
'{self._joined_on}',
|
||||||
|
{"" if self._leaved_on is None else f"'{self._leaved_on}',"}
|
||||||
'{self._created_at}',
|
'{self._created_at}',
|
||||||
'{self._modified_at}'
|
'{self._modified_at}'
|
||||||
);
|
);
|
||||||
@ -133,7 +118,8 @@ class UserJoinedGameServer(TableABC):
|
|||||||
return str(
|
return str(
|
||||||
f"""
|
f"""
|
||||||
UPDATE `UserJoinedGameServer`
|
UPDATE `UserJoinedGameServer`
|
||||||
SET `LeavedOn` = '{self._leaved_on}',
|
SET
|
||||||
|
{"" if self._leaved_on is None else f"`LeavedOn` = '{self._leaved_on}',"}
|
||||||
`LastModifiedAt` = '{self._modified_at}'
|
`LastModifiedAt` = '{self._modified_at}'
|
||||||
WHERE `Id` = {self._id};
|
WHERE `Id` = {self._id};
|
||||||
"""
|
"""
|
||||||
|
@ -97,28 +97,14 @@ class UserJoinedServer(TableABC):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def insert_string(self) -> str:
|
def insert_string(self) -> str:
|
||||||
if self._leaved_on is not None:
|
|
||||||
return str(
|
return str(
|
||||||
f"""
|
f"""
|
||||||
INSERT INTO `UserJoinedServers` (
|
INSERT INTO `UserJoinedServers` (
|
||||||
`UserId`, `JoinedOn`, `LeavedOn`, `CreatedAt`, `LastModifiedAt`
|
`UserId`, `JoinedOn`, {"" if self._leaved_on is None else "`LeavedOn`,"} `CreatedAt`, `LastModifiedAt`
|
||||||
) VALUES (
|
|
||||||
{self._user.id},
|
|
||||||
'{self._joined_on}',
|
|
||||||
'{self._leaved_on}',
|
|
||||||
'{self._created_at}',
|
|
||||||
'{self._modified_at}'
|
|
||||||
);
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
return str(
|
|
||||||
f"""
|
|
||||||
INSERT INTO `UserJoinedServers` (
|
|
||||||
`UserId`, `JoinedOn`, `CreatedAt`, `LastModifiedAt`
|
|
||||||
) VALUES (
|
) VALUES (
|
||||||
{self._user.id},
|
{self._user.id},
|
||||||
'{self._joined_on}',
|
'{self._joined_on}',
|
||||||
|
{"" if self._leaved_on is None else f"'{self._leaved_on}',"}
|
||||||
'{self._created_at}',
|
'{self._created_at}',
|
||||||
'{self._modified_at}'
|
'{self._modified_at}'
|
||||||
);
|
);
|
||||||
@ -130,7 +116,8 @@ class UserJoinedServer(TableABC):
|
|||||||
return str(
|
return str(
|
||||||
f"""
|
f"""
|
||||||
UPDATE `UserJoinedServers`
|
UPDATE `UserJoinedServers`
|
||||||
SET `LeavedOn` = '{self._leaved_on}',
|
SET
|
||||||
|
{"" if self._leaved_on is None else f"`LeavedOn` = '{self._leaved_on}',"}
|
||||||
`LastModifiedAt` = '{self._modified_at}'
|
`LastModifiedAt` = '{self._modified_at}'
|
||||||
WHERE `UserId` = {self._user.id};
|
WHERE `UserId` = {self._user.id};
|
||||||
"""
|
"""
|
||||||
|
@ -105,30 +105,15 @@ class UserJoinedVoiceChannel(TableABC):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def insert_string(self) -> str:
|
def insert_string(self) -> str:
|
||||||
if self._leaved_on is not None:
|
|
||||||
return str(
|
return str(
|
||||||
f"""
|
f"""
|
||||||
INSERT INTO `UserJoinedVoiceChannel` (
|
INSERT INTO `UserJoinedVoiceChannel` (
|
||||||
`UserId`, `DiscordChannelId`, `JoinedOn`, `LeavedOn`, `CreatedAt`, `LastModifiedAt`
|
`UserId`, `DiscordChannelId`, `JoinedOn`, {"" if self._leaved_on is None else "`LeavedOn`,"} `CreatedAt`, `LastModifiedAt`
|
||||||
) VALUES (
|
|
||||||
{self._user.id},
|
|
||||||
{self._channel_id},
|
|
||||||
'{self._joined_on}',
|
|
||||||
'{self._leaved_on}',
|
|
||||||
'{self._created_at}',
|
|
||||||
'{self._modified_at}'
|
|
||||||
);
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
return str(
|
|
||||||
f"""
|
|
||||||
INSERT INTO `UserJoinedVoiceChannel` (
|
|
||||||
`UserId`, `DiscordChannelId`, `JoinedOn`, `CreatedAt`, `LastModifiedAt`
|
|
||||||
) VALUES (
|
) VALUES (
|
||||||
{self._user.id},
|
{self._user.id},
|
||||||
{self._channel_id},
|
{self._channel_id},
|
||||||
'{self._joined_on}',
|
'{self._joined_on}',
|
||||||
|
{"" if self._leaved_on is None else f"'{self._leaved_on}',"}
|
||||||
'{self._created_at}',
|
'{self._created_at}',
|
||||||
'{self._modified_at}'
|
'{self._modified_at}'
|
||||||
);
|
);
|
||||||
@ -140,7 +125,8 @@ class UserJoinedVoiceChannel(TableABC):
|
|||||||
return str(
|
return str(
|
||||||
f"""
|
f"""
|
||||||
UPDATE `UserJoinedVoiceChannel`
|
UPDATE `UserJoinedVoiceChannel`
|
||||||
SET `LeavedOn` = '{self._leaved_on}',
|
SET
|
||||||
|
{"" if self._leaved_on is None else f"`LeavedOn` = '{self._leaved_on}',"}
|
||||||
`LastModifiedAt` = '{self._modified_at}'
|
`LastModifiedAt` = '{self._modified_at}'
|
||||||
WHERE `JoinId` = {self._join_id};
|
WHERE `JoinId` = {self._join_id};
|
||||||
"""
|
"""
|
||||||
|
@ -52,6 +52,9 @@ class BaseReactionHandler:
|
|||||||
__name__,
|
__name__,
|
||||||
f"{log_msg} to message {LogMessageHelper.get_log_string(message)}",
|
f"{log_msg} to message {LogMessageHelper.get_log_string(message)}",
|
||||||
)
|
)
|
||||||
|
if member == message.author:
|
||||||
|
self._logger.debug(__name__, f"Skipping reaction handling")
|
||||||
|
return
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._logger.error(__name__, f"Getting message for reaction logging failed", e)
|
self._logger.error(__name__, f"Getting message for reaction logging failed", e)
|
||||||
self._logger.info(__name__, f"{log_msg} to message {payload.message_id}")
|
self._logger.info(__name__, f"{log_msg} to message {payload.message_id}")
|
||||||
|
@ -375,8 +375,6 @@ class DatabaseOnReadyEvent(OnReadyABC):
|
|||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
self._logger.debug(__name__, f"Module {type(self)} started")
|
self._logger.debug(__name__, f"Module {type(self)} started")
|
||||||
|
|
||||||
await self._seeder.seed()
|
|
||||||
|
|
||||||
self._check_known_users()
|
self._check_known_users()
|
||||||
self._check_servers()
|
self._check_servers()
|
||||||
self._check_clients()
|
self._check_clients()
|
||||||
@ -385,5 +383,7 @@ class DatabaseOnReadyEvent(OnReadyABC):
|
|||||||
self._check_user_joins_vc()
|
self._check_user_joins_vc()
|
||||||
self._check_user_joined_gs()
|
self._check_user_joined_gs()
|
||||||
|
|
||||||
|
await self._seeder.seed()
|
||||||
|
|
||||||
self._validate_init_time()
|
self._validate_init_time()
|
||||||
self._logger.trace(__name__, f"Module {type(self)} stopped")
|
self._logger.trace(__name__, f"Module {type(self)} stopped")
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import discord
|
import discord
|
||||||
|
from cpl_core.database.context import DatabaseContextABC
|
||||||
from cpl_discord.container import Guild
|
from cpl_discord.container import Guild
|
||||||
from cpl_discord.service import DiscordBotServiceABC
|
from cpl_discord.service import DiscordBotServiceABC
|
||||||
from discord import Permissions, Colour
|
from discord import Permissions, Colour
|
||||||
@ -21,6 +22,7 @@ class LevelSeeder(DataSeederABC):
|
|||||||
level_repo: LevelRepositoryService,
|
level_repo: LevelRepositoryService,
|
||||||
servers: ServerRepositoryABC,
|
servers: ServerRepositoryABC,
|
||||||
level: LevelService,
|
level: LevelService,
|
||||||
|
db: DatabaseContextABC,
|
||||||
bot: DiscordBotServiceABC,
|
bot: DiscordBotServiceABC,
|
||||||
):
|
):
|
||||||
DataSeederABC.__init__(self)
|
DataSeederABC.__init__(self)
|
||||||
@ -29,6 +31,7 @@ class LevelSeeder(DataSeederABC):
|
|||||||
self._levels = level_repo
|
self._levels = level_repo
|
||||||
self._servers = servers
|
self._servers = servers
|
||||||
self._level = level
|
self._level = level
|
||||||
|
self._db = db
|
||||||
self._bot = bot
|
self._bot = bot
|
||||||
|
|
||||||
self._level_header = levels.level_header
|
self._level_header = levels.level_header
|
||||||
@ -51,6 +54,7 @@ class LevelSeeder(DataSeederABC):
|
|||||||
if levels is None or levels.where(lambda l: l.name == level.name).first_or_default() is None:
|
if levels is None or levels.where(lambda l: l.name == level.name).first_or_default() is None:
|
||||||
self._levels.add_level(level)
|
self._levels.add_level(level)
|
||||||
self._logger.debug(__name__, f"Saved level {level.name}")
|
self._logger.debug(__name__, f"Saved level {level.name}")
|
||||||
|
self._db.save_changes()
|
||||||
except discord.errors.Forbidden as e:
|
except discord.errors.Forbidden as e:
|
||||||
self._logger.error(__name__, f"Creating level failed", e)
|
self._logger.error(__name__, f"Creating level failed", e)
|
||||||
level.permissions = 0
|
level.permissions = 0
|
||||||
|
Loading…
Reference in New Issue
Block a user