This repository has been archived by the owner on Apr 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
122 lines (90 loc) · 3.53 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from discord import Embed
from discord.ext.commands import Cog, Context, Command, CommandError
from config import config
import re
from translations import Translations
import json
async def send_help(ctx: Context):
translation = get_language_config_by_id(ctx.guild.id)
embed = Embed(title=translation.f_help_embed_title("BibleBot"), color=0x03a1fc)
embed.add_field(name=translation.help_embed_quote_title, value=translation.help_embed_quote_value, inline=True)
if await can_run_command(ctx.bot.get_command("settings"), ctx):
embed.add_field(name=translation.settings_name,
value=translation.f_help_embed_settings_value(await get_prefix(ctx.message)), inline=False)
embed.add_field(name=translation.help_embed_invite_title, value="[" + translation.help_embed_invite_link + "](https://discord.com/oauth2/authorize?client_id=689383347545440313&permissions=522304&scope=bot)")
await ctx.send(embed=embed)
async def can_run_command(command: Command, ctx: Context):
try:
return await command.can_run(ctx)
except CommandError:
return False
def get_bible_queries(message: str):
m = re.findall("\\[\\w+ \\d+:\\d+[0-9,-]+\\]", message)
m = list(dict.fromkeys(m))
return [i.replace("[", "").replace("]", "") for i in m]
def add_cogs(bot, *cogs):
for cog_c in cogs:
if cog_c is None:
continue
cog: Cog = cog_c(bot)
bot.add_cog(cog)
def get_language(id):
languages = config.language
try:
return languages[str(id)]
except KeyError:
add_guild_by_id(id)
config.reload()
languages = config.language
return languages[str(id)]
def get_language_config(language):
return Translations(language)
def get_language_config_by_id(id):
return Translations(get_language(id))
def get_default_bible_translation(id):
return Translations(get_language(id)).default_translation
def get_translation(id):
translations = config.translation
try:
return translations[str(id)]
except KeyError:
add_guild_by_id(id)
config.reload()
translations = config.translation
return translations[str(id)]
def get_possible_translations(id):
return Translations(get_language(id)).bible_translations
async def get_prefix_client(client, message):
prefixes = config.prefix
try:
return prefixes[str(message.guild.id)], f"<@!{client.user.id}> ", f"<@{client.user.id}> "
except KeyError:
add_guild(message.guild)
config.reload()
prefixes = config.prefix
return prefixes[str(message.guild.id)], f"<@!{client.user.id}> ", f"<@{client.user.id}> "
async def get_prefix(message):
prefixes = config.prefix
try:
return prefixes[str(message.guild.id)]
except KeyError:
add_guild(message.guild)
config.reload()
return prefixes[str(message.guild.id)]
def add_guild(guild):
add_guild_by_id(guild.id)
def add_guild_by_id(id):
# prefixes = config.prefix
# translations = config.language
# languages = config.translation
# languages[str(id)] = "en"
# prefixes[str(id)] = "."
# translations[str(id)] = get_default_bible_translation(str(id))
# config.save("prefix", prefixes)
# config.save("language", languages)
# config.save("translation", translations)
data = json.load(open("config.json"))
data["prefix"][str(id)] = "."
data["language"][str(id)] = "en"
data["translation"][str(id)] = "kjv"
json.dump(data, open("config.json", "w"), indent=4)