def get(ctx, mod, key): if ctx.guild: loc = db.read("serversettings", ctx.guild.id, "locale") or db.read( "settings", 0, "locale") else: loc = db.read("settings", 0, "locale") return load(loc, mod, key)
async def info(self, ctx): owner = self.bot.get_user(config["owner"]) if owner is None: owner = loc.get(ctx, mn, "info_unknown") ping = int(self.bot.latency * 1000) embed = discord.Embed(title=loc.get(ctx, mn, "info_about"), color=discord.Color.teal()) bot = self.bot.user start_at = datetime.strptime(db.read("temp", 1, "start_time"), "%Y-%m-%d %H:%M:%S") diff = datetime.now() - start_at h, r = divmod(int(diff.total_seconds()), 3600) m, s = divmod(r, 60) d, h = divmod(h, 24) up = f"{d}:{h}:{m}:{s}" embed.set_author(name=bot.name, icon_url=str(bot.avatar_url)) embed.add_field(name=loc.get(ctx, mn, "info_bot_title"), value=loc.get(ctx, mn, "info_bot").format(owner, len(self.bot.users), len(self.bot.guilds), db.read("settings", 0, "prefix"), len(self.bot.cogs)), inline=True) embed.add_field(name=loc.get(ctx, mn, "info_other_title"), value=loc.get(ctx, mn, "info_other").format(ping, self.bot.user.id, len(self.bot.cached_messages), discord.__version__, up), inline=True) embed.set_footer(text=db.read("settings", 0, "name")) await ctx.send(embed=embed)
async def on_ready(): print(loc.load(dl, mn, "logged_in_as").format(bot.user)) bot.remove_command("help") for p in config["loadPlugins"]: print(loc.load(dl, mn, "loading_ext").format(p)) try: bot.load_extension(p) except commands.ExtensionAlreadyLoaded: print(loc.load(dl, mn, "loading_ext_failed")) await bot.change_presence( status=tools.get_status(db.read("settings", 0, "status")), activity=tools.get_presence(db.read("settings", 0, "presence_type"), db.read("settings", 0, "presence_value")))
async def set_invite(self, ctx, link: str = None): if not link: await ctx.send(loc.get(ctx, mn, "config_invite").format(db.read("settings", 0, "invite") or inv_d + str(ctx.me.id))) return if link == "default": db.delete("settings", 0, "invite") elif link == "off": db.write("settings", 0, "invite", "off") await ctx.send(loc.get(ctx, mn, "config_invite_disabled")) return else: if not link.startswith("https://"): await ctx.send(loc.get(ctx, mn, "config_invite_invalid")) return db.write("settings", 0, "invite", link) await ctx.send(loc.get(ctx, mn, "config_invite_set").format(db.read("settings", 0, "invite") or inv_d + str(ctx.me.id)))
async def summary(bot, ctx): cl = "" cogs = sorted(bot.cogs) for cog in cogs: cl = cl + f"`{cog}` {loc.get(ctx, dn, cog.lower())}\n" embed = discord.Embed(title=loc.get(ctx, mn, "help_title"), description=loc.get(ctx, mn, "about_bot").format(db.read("settings", 0, "name")), color=discord.Color.teal()) embed.add_field(name=loc.get(ctx, mn, "help_title"), value=loc.get(ctx, mn, "help_how").format(prefix), inline=False) embed.add_field(name=loc.get(ctx, mn, "modules_all"), value=cl[:-1], inline=False) await ctx.send(embed=embed)
async def invite(self, ctx): inv = db.read("settings", 0, "invite") or inv_d + str(ctx.me.id) if inv == "off": await ctx.send(loc.get(ctx, mn, "invite_disabled")) else: await ctx.send(loc.get(ctx, mn, "invite").format(inv))
import discord from discord.ext import commands as discord_commands from utils import db, tools from utils import locale as loc mn = "utils.help" dn = "commands" prefix = db.read("settings", 0, "prefix") async def summary(bot, ctx): cl = "" cogs = sorted(bot.cogs) for cog in cogs: cl = cl + f"`{cog}` {loc.get(ctx, dn, cog.lower())}\n" embed = discord.Embed(title=loc.get(ctx, mn, "help_title"), description=loc.get(ctx, mn, "about_bot").format(db.read("settings", 0, "name")), color=discord.Color.teal()) embed.add_field(name=loc.get(ctx, mn, "help_title"), value=loc.get(ctx, mn, "help_how").format(prefix), inline=False) embed.add_field(name=loc.get(ctx, mn, "modules_all"), value=cl[:-1], inline=False) await ctx.send(embed=embed) async def send_help(bot, ctx): embeds = [] cogs = bot.cogs ordered_cogs = sorted(cogs) for cog in ordered_cogs: cmds = cogs[cog].get_commands() embeds = _paginate(ctx, cmds, embeds)
import sys from utils import db args = sys.argv if len(args) == 1: print("db_config.py: small utility to input into the Alter database") print("this only allows to edit the 'settings' table") print(f"- ./{args[0]} <key>: show value for key") print(f"- ./{args[0]} <key> <value>: set value for key") print(f"Example: ./{args[0]} name Alter") if len(args) == 2: val = db.read("settings", 0, args[1]) if val: print(f"{args[1]}: {val}") else: print(f"'{args[1]}' is not present in the database.") print( "Hint: Values are case-sensitive, please make sure you typed the value correctly." ) exit(2) if len(args) > 2: value = " ".join(args[2:]) db.write("settings", 0, args[1], value) print("Value recorded to database.") exit(0)
import discord from discord.ext import commands from utils.dataIO import dataIO from utils import db, tools from utils import locale as loc from utils import help from datetime import datetime config = dataIO.load_json("data/config.json") mn = "alter" dl = db.read("settings", 0, "locale") token = config["token"] prefix = db.read("settings", 0, "prefix") bot = commands.AutoShardedBot(prefix, intents=discord.Intents.all()) @bot.event async def on_ready(): print(loc.load(dl, mn, "logged_in_as").format(bot.user)) bot.remove_command("help") for p in config["loadPlugins"]: print(loc.load(dl, mn, "loading_ext").format(p)) try: bot.load_extension(p) except commands.ExtensionAlreadyLoaded: print(loc.load(dl, mn, "loading_ext_failed")) await bot.change_presence( status=tools.get_status(db.read("settings", 0, "status")), activity=tools.get_presence(db.read("settings", 0, "presence_type"), db.read("settings", 0, "presence_value")))