From f00ff8d3450b3939f5ef9edbde0630d5103e93ea Mon Sep 17 00:00:00 2001 From: Romain J Date: Thu, 13 May 2021 16:44:18 +0200 Subject: [PATCH] fix(core:i18n): fix crash for DMs --- tuxbot/cogs/Admin/models/alias.py | 24 ------------------------ tuxbot/cogs/Admin/models/warns.py | 24 ------------------------ tuxbot/core/i18n.py | 7 +++++-- 3 files changed, 5 insertions(+), 50 deletions(-) delete mode 100644 tuxbot/cogs/Admin/models/alias.py delete mode 100644 tuxbot/cogs/Admin/models/warns.py diff --git a/tuxbot/cogs/Admin/models/alias.py b/tuxbot/cogs/Admin/models/alias.py deleted file mode 100644 index 2ba0073..0000000 --- a/tuxbot/cogs/Admin/models/alias.py +++ /dev/null @@ -1,24 +0,0 @@ -import tortoise -from tortoise import fields - - -class Alias(tortoise.Model): - id = fields.BigIntField(pk=True) - user_id = fields.BigIntField() - alias = fields.TextField(max_length=255) - command = fields.TextField(max_length=255) - guild = fields.BigIntField() - - class Meta: - table = "aliases" - - def __str__(self): - return ( - f"" - ) - - __repr__ = __str__ diff --git a/tuxbot/cogs/Admin/models/warns.py b/tuxbot/cogs/Admin/models/warns.py deleted file mode 100644 index 4bda9fc..0000000 --- a/tuxbot/cogs/Admin/models/warns.py +++ /dev/null @@ -1,24 +0,0 @@ -import tortoise -from tortoise import fields - - -class Warn(tortoise.Model): - id = fields.BigIntField(pk=True) - server_id = fields.BigIntField() - user_id = fields.BigIntField() - reason = fields.TextField(max_length=255) - created_at = fields.DatetimeField() - - class Meta: - table = "warns" - - def __str__(self): - return ( - f"" - ) - - __repr__ = __str__ diff --git a/tuxbot/core/i18n.py b/tuxbot/core/i18n.py index 88d7d5e..465dd7b 100644 --- a/tuxbot/core/i18n.py +++ b/tuxbot/core/i18n.py @@ -75,9 +75,12 @@ class Translator: if user_locale: return self.translations[user_locale][untranslated] - guild_locale = search_for( - config.Servers, ctx.guild.id, "locale", None + guild_locale = ( + search_for(config.Servers, ctx.guild.id, "locale", None) + if ctx.guild + else None ) + if guild_locale: return self.translations[guild_locale][untranslated]