Skip to content

Commit

Permalink
Merge pull request #41 from EncryptEx/FIX-Various-changes
Browse files Browse the repository at this point in the history
FIX: Fixed various bugs and errors on language support
  • Loading branch information
EncryptEx authored Aug 25, 2023
2 parents b62889a + 3f39619 commit e8e4883
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 56 deletions.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.formatting.provider": "none"
}
110 changes: 72 additions & 38 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ async def getAllWarns(userid: int, guildid: int):
emojis = str(c)
ddt = int(str(dt)[:str(dt).find(".")])
allwarns.append(
f"- **ID: {emojis}** Reason: ``{SubReason}`` <t:{ddt}:R>")

await GetTranslatedText(guildid, "warns_line_loop", EMOJIS=emojis, SUBREASON=SubReason, DDT=ddt))
c = c + 1
return allwarns

Expand Down Expand Up @@ -299,44 +298,41 @@ async def AddDeniedWord(guildid: int, userid: int, word: str):
return True


async def GetSettings(guildid: int):
async def GetSettings(guildid: int, index:int):
cur.execute("SELECT * FROM settings WHERE guildid = ? LIMIT 1",
(guildid, ))
rows = cur.fetchall()
if len(rows) > 0:
return rows[0]
return rows[0][index]
else:
return 0 # default is off


async def GetTranslatedText(guildid: int, index: str, **replace):
global languages

dbLanguageRecord = await GetSettings(guildid)
if dbLanguageRecord == 0:
currentLanguage = "en" # not saved config in db
else:
dbLanguageRecord = dbLanguageRecord[2] # [2] stands for language col
currentLanguage = "en" if dbLanguageRecord == None else dbLanguageRecord
dbLanguageRecord = await GetSettings(guildid, 2)
currentLanguage = "en" if dbLanguageRecord == 0 or dbLanguageRecord == None else dbLanguageRecord

text = languages[currentLanguage].get(index, "Word not translated yet.")
for oldString, newString in replace.items():
text = text.replace("{" + oldString + "}", str(newString))
return text


async def SaveSetting(guildid: int, module: str, value: int):
async def SaveSetting(guildid: int, module: str, value: str):
cur.execute("SELECT * FROM settings WHERE guildid = ? LIMIT 1",
(guildid, ))
rows = cur.fetchall()

# print(rows)
if len(
rows
) > 0: # cur.execute('INSERT INTO foo (a,b) values (?,?)', (strA, strB))
query = f"""UPDATE settings
SET {module} = {value}
WHERE guildid={guildid} """
cur.execute(query)
SET {module}=?
WHERE guildid=?"""
cur.execute(query, (value, guildid))
else:
cur.execute(
"""INSERT OR IGNORE INTO settings (guildid, automod)
Expand Down Expand Up @@ -495,9 +491,9 @@ async def on_message(message):
return
if message.content == "" or message.content == None:
return
settings = await GetSettings(message.guild.id)
settings = await GetSettings(message.guild.id, 1)

if settings != 0 and settings[1] != 1:
if settings != 1:
return # user has disabled Automod or does not have it installed
words = message.content.split()
allowed_words_guild_list = await GetAutomodCustomWords(
Expand Down Expand Up @@ -612,7 +608,7 @@ async def on_ready():
print("Sent message to #" + str(chnl))


debug = True
debug = False # ALWAYS FALSE!


@bot.slash_command(guild_only=True,
Expand Down Expand Up @@ -909,7 +905,7 @@ async def seewarns(ctx, member: discord.Member):
"data": {
"datasets": [{
"fill": False,
"label": [f"Warns of {filterMember(member)}"],
"label": [await GetTranslatedText(ctx.guild.id, "seewarns_chart_title", MEMBER=filterMember(member))],
"lineTension": 0,
"backgroundColor": "#7289DA",
"borderColor": "#7289DA",
Expand Down Expand Up @@ -1000,7 +996,7 @@ async def unwarn(ctx, member: discord.Member, id: int = None, *, reason=None):
)
embed.set_thumbnail(url=member.display_avatar)
warn = await Removewarn(member.id, ctx.guild.id, id)
s = "s" if warn != 1 else ""
s = await GetTranslatedText(ctx.guild.id, "plural_warn") if warn != 1 else await GetTranslatedText(ctx.guild.id, "singular_warn")
congrats = "Yey! :tada:" if warn == 0 else ""
embed.add_field(
name=await GetTranslatedText(ctx.guild.id, "automod_count_title"),
Expand Down Expand Up @@ -1202,7 +1198,7 @@ async def restart(ctx):
async def setdelay(ctx, seconds: float, reason: str = ""):
m = (await GetTranslatedText(ctx.guild.id, "modified") if seconds > 0.0
else await GetTranslatedText(ctx.guild.id, "removed"))
reason = "for " + reason if reason != "" and reason != None else ""
reason = ((await GetTranslatedText(ctx.guild.id, "for"))+ reason) if reason != "" and reason != None else ""
embed = Embed(
title=await GetTranslatedText(ctx.guild.id,
"setdelay_title",
Expand Down Expand Up @@ -1427,25 +1423,50 @@ async def invite(ctx):
@option(
"value",
description="Select on/off",
autocomplete=discord.utils.basic_autocomplete(["on", "off"]),
autocomplete=discord.utils.basic_autocomplete(["on", "off", "en", "cat"]),
)
async def settings(ctx, module: str = None, value: str = None):
languagesOptions = [k for k,_ in languages.items()]
if module != None and value != None:
if module in modules and value == "on" or value == "off":
value = 1 if value == "on" else 0
await SaveSetting(ctx.guild.id, module, value)
action = "enabled" if value else "disabled"
await ctx.respond(
await GetTranslatedText(ctx.guild.id,
"settings_module",
MODULE=module,
ACTION=action),
ephemeral=True,
)
return
if module in modules:
if module=="automod":
value = 1 if value == "on" else 0
await SaveSetting(ctx.guild.id, module, value)
action = "enabled" if value else "disabled"
await ctx.respond(
await GetTranslatedText(ctx.guild.id,
"settings_module",
MODULE=module,
ACTION=action),
ephemeral=True,
)

elif module=="language":
if(value in languagesOptions):
await SaveSetting(ctx.guild.id, module, value)
action = "set to " + value
await ctx.respond(
await GetTranslatedText(ctx.guild.id,
"settings_module",
MODULE=module,
ACTION=action),
ephemeral=True,
)
else:
await ctx.respond(
await GetTranslatedText(ctx.guild.id, "error_settings_syntax", COMMAND="/settings language "+'/'.join(languagesOptions)),
ephemeral=True)

else:
await ctx.respond(
await GetTranslatedText(ctx.guild.id, "error_settings_syntax", COMMAND="/settings automod on/off"),
ephemeral=True,
)
return

else:
await ctx.respond(
await GetTranslatedText(ctx.guild.id, "error_settings_syntax"),
await GetTranslatedText(ctx.guild.id, "error_settings_syntax", COMMAND="/settings module value"),
ephemeral=True,
)
return
Expand All @@ -1455,7 +1476,7 @@ async def settings(ctx, module: str = None, value: str = None):
"settings_description"),
)
print("getting settings from discord.Guild.id", ctx.guild.id)
automodStatus = (await GetSettings(ctx.guild.id))[1]
automodStatus = await GetSettings(ctx.guild.id, 1)
automodStatustr = "**✅ ON**" if automodStatus else "**❌ OFF**"
recommendedactivityAutomod = (
await GetTranslatedText(ctx.guild.id,
Expand All @@ -1467,12 +1488,25 @@ async def settings(ctx, module: str = None, value: str = None):
embed.add_field(
name=await GetTranslatedText(ctx.guild.id, "help_automod_title"),
value=await GetTranslatedText(
ctx.guild,
"automod_status",
ctx.guild.id,
"settings_status",
STATUS=automodStatustr,
RECOMMENDED=recommendedactivityAutomod,
),
inline=True,
inline=False,
)
language = await GetSettings(ctx.guild.id, 2)
languagestr = F"**{language}**" if language else "**EN (English)**"
recommendedacmdLang = await GetTranslatedText(ctx.guild.id, "error_settings_syntax", COMMAND="/settings language "+'/'.join(languagesOptions))
embed.add_field(
name=await GetTranslatedText(ctx.guild.id, "help_language_title"),
value=await GetTranslatedText(
ctx.guild.id,
"settings_status",
STATUS=languagestr,
RECOMMENDED=recommendedacmdLang,
),
inline=False,
)
embed.set_footer(
text=await GetTranslatedText(ctx.guild.id,
Expand Down
26 changes: 16 additions & 10 deletions langs/cat.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"user": "usuari",
"reason": "motiu",
"help_automod_title": "Serveis d'AutoMod :robot:",
"help_automod_description": "Detecta paraules obscenes i adverteix automàticament. \nUtilitza una base de dades de més de 880 paraules obscenes \n\n Personalitza-ho amb:\n {COMMAND_PREFIX}automod [afegir/eliminar] [paraula]\nO activa/desactiva-ho amb:\n{COMMAND_PREFIX}configuració [automod] [activar/desactivar]",
"help_automod_description": "Detecta paraules obscenes i adverteix automàticament. \nUtilitza una base de dades de més de 880 paraules obscenes \n\n Personalitza-ho amb:\n {COMMAND_PREFIX}automod [add/remove] [paraula]\nO activa/desactiva-ho amb:\n{COMMAND_PREFIX}configuració [automod] [activar/desactivar]",
"help_chatmod_title": "Comandes de Moderació de Xat :file_folder:",
"help_chatmod_description": "{COMMAND_PREFIX}setdelay [segons] <motiu>\n{COMMAND_PREFIX}mute [usuari] <motiu>\n{COMMAND_PREFIX}unmute [usuari] <motiu>\n{COMMAND_PREFIX]lock <canal> <motiu>\n{COMMAND_PREFIX}unlock <canal> <motiu>\n",
"help_chatmod_description": "{COMMAND_PREFIX}setdelay [segons] <motiu>\n{COMMAND_PREFIX}mute [usuari] <motiu>\n{COMMAND_PREFIX}unmute [usuari] <motiu>\n{COMMAND_PREFIX}lock <canal> <motiu>\n{COMMAND_PREFIX}unlock <canal> <motiu>\n",
"help_various_title": "Utilitats Diverses :screwdriver:",
"help_various_description": "{COMMAND_PREFIX}whois [usuari]",
"help_links_title": "Enllaços Útils: :link:",
"help_links_description": "[:classical_building: Suport del Hammer Bot](https://discord.gg/fMSyQA6)\n[:link: Enllaç d'Invitació del Hammer](https://discordapp.com/api/oauth2/authorize?client_id=591633652493058068&permissions=8&scope=bot)\n[:newspaper: Vota per al Hammer](https://top.gg/bot/591633652493058068)}",
"help_links_description": "[:classical_building: Suport del Hammer Bot](https://discord.gg/fMSyQA6)\n[:link: Enllaç d'Invitació del Hammer](https://discordapp.com/api/oauth2/authorize?client_id=591633652493058068&permissions=8&scope=bot)\n[:newspaper: Vota per al Hammer](https://top.gg/bot/591633652493058068)]",
"help_commands_title": "Comandes d'Ajuda",
"help_commands_description": "{COMMAND_PREFIX}help\n{COMMAND_PREFIX}invite\n{COMMAND_PREFIX}suggest [suggeriment]",
"footer_executed_by": "Hammer | Comanda executada per {USERNAME}",
Expand Down Expand Up @@ -54,17 +54,20 @@
"unwarn_msg": "S'ha eliminat l'avís per {REASON}",
"unwarn_title": "{MEMBER} ha estat desadvertit! :hammer_pick:",
"unwarn_description": "L'usuari {MEMBER} ha estat desadvertit per {REASON}",
"unwarn_count_with_success": "L'usuari {MEMBER} té ara {WARN} avís{S}. {CONGRATS}",
"clearwarns_msg": "Els teus avíss s'han eliminat per {REASON}",
"clearwarns_description": "L'usuari {MEMBER} no té cap avís per {REASON}",
"clearwarns_title": "Els avís de {MEMBER} s'han eliminat! :hammer_pick:",
"plural_warn": "avisos",
"singular_warn": "avís",
"unwarn_count_with_success": "L'usuari {MEMBER} té ara {WARN} {S}. {CONGRATS}",
"clearwarns_msg": "Els teus avisos s'han eliminat per {REASON}",
"clearwarns_description": "L'usuari {MEMBER} ja no té cap avís per {REASON}",
"clearwarns_title": "Els avisos d'{MEMBER} s'han eliminat! :hammer_pick:",
"error_automod_syntax": "Sintaxi incorrecta, si us plau, utilitza /automod afegir/eliminar [paraula]",
"automod_success_action": "La paraula ||{WORD}|| s'ha {ACTION}at {PREP} la llista de paraules obscenes amb èxit. :tools:",
"error_automod": "No s'ha pogut desar la paraula ||{WORD}|| a la base de dades. Si us plau, posa't en contacte amb l'administrador o el desenvolupador del bot per obtenir més informació.",
"modified": "modificat",
"removed": "eliminat",
"setdelay_title": "Retard {M} a #{CHANNEL} :hammer_pick:",
"setdelay_description": "Aquest canal té ara un retard de **{SECONDS}** segons per {REASON}",
"for": "per ",
"setdelay_description": "Aquest canal té ara un retard de **{SECONDS}** segons {REASON}",
"mute_title": "Usuari Silenciat: {MEMBER}",
"mute_description": "L'usuari {MENTION} ha estat silenciat per {REASON}",
"mute_msg": ":no_entry: Has estat silenciat de: {GUILD} per {REASON}",
Expand All @@ -81,10 +84,13 @@
"enabled": "activat",
"disabled": "desactivat",
"settings_module": "El mòdul {MODULE} s'ha {ACTION} amb èxit!",
"error_settings_syntax": "Utilitza: ``/settings mòdul on/off``",
"error_settings_syntax": "Utilitza: ``{COMMAND}``",
"settings_title": "Configuració del Hammer Bot :hammer_pick:",
"settings_description": "Aquí pots activar o desactivar alguns mòduls",
"settings_enable_automod": "Activa'l amb ``{COMMAND_PREFIX}settings automod on``",
"settings_disable_automod": "Desactiva'l amb: ``{COMMAND_PREFIX}settings automod off``",
"autmod_status": "Estat actual: {STATUS}\n {RECOMMENDED}"
"settings_status": "Estat actual: {STATUS}\n {RECOMMENDED}",
"help_language_title": "Idioma del Hammer :globe_with_meridians:",
"warns_line_loop": "- **ID: {EMOJIS}** Raó: ``{SUBREASON}`` <t:{DDT}:R>",
"seewarns_chart_title": "Avisos d'{MEMBER}"
}
17 changes: 12 additions & 5 deletions langs/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
"unwarn_msg": "You have been unwarned for {REASON}",
"unwarn_title": "{MEMBER} has been unwarned! :hammer_pick:",
"unwarn_description": "The user {MEMBER} has been unwarned for {REASON}",
"unwarn_count_with_success": "The user {MEMBER} has now {WARN} warn{S}. {CONGRATS}",
"plural_warn": "warns",
"singular_warn": "warn",
"unwarn_count_with_success": "The user {MEMBER} has now {WARN} {S}. {CONGRATS}",
"clearwarns_msg": "Your warns have been cleared for {REASON}",
"clearwarns_description": "The user {MEMBER} has 0 warns for {REASON}",
"clearwarns_title": "The warns of {MEMBER} have been removed! :hammer_pick:",
Expand All @@ -64,7 +66,8 @@
"modified": "modified",
"removed": "removed",
"setdelay_title": "Delay {M} on #{CHANNEL} :hammer_pick:",
"setdelay_description": "This channel now has a delay of **{SECONDS}** seconds for {REASON}",
"for": "for ",
"setdelay_description": "This channel now has a delay of **{SECONDS}** seconds {REASON}",
"mute_title": "User Muted: {MEMBER}",
"mute_description": "User {MENTION} has been muted for {REASON}",
"mute_msg": ":no_entry: You have been muted from: {GUILD} for {REASON}",
Expand All @@ -81,10 +84,14 @@
"enabled": "enabled",
"disabled": "disabled",
"settings_module": "Module {MODULE} {ACTION} successfully!",
"error_settings_syntax": "Use: ``/settings module on/off``",
"error_settings_syntax": "Use: `{COMMAND}`",
"settings_title": "Hammer Bot Settings :hammer_pick:",
"settings_description": "Here you can enable or disable some modules",
"settings_enable_automod": "Enable it by doing ``{COMMAND_PREFIX}settings automod on``",
"settings_disable_automod": "Disable it by doing: ``{COMMAND_PREFIX}settings automod off``",
"autmod_status": "Actual status: {STATUS}\n {RECOMMENDED}"
}
"settings_status": "Actual status: {STATUS}\n {RECOMMENDED}",
"help_language_title": "Hammer's Language :globe_with_meridians:",
"warns_line_loop": "- **ID: {EMOJIS}** Reason: ``{SUBREASON}`` <t:{DDT}:R>",
"seewarns_chart_title": "Warns of {MEMBER}"

}
Loading

0 comments on commit e8e4883

Please sign in to comment.