コード例 #1
0
ファイル: tvault.py プロジェクト: ryanegenlangston1993/hrtrn
    async def fulfill(self, ctx, request):
        '''
        Indicates the fulfillment of the specified request
        '''

        if dbutils.read("requests")[request]["fulfilled"]:
            embed = discord.Embed()
            embed.title = "Request Already Fulfilled"
            embed.description = f'Request #{request} has already been fulfilled by ' \
                                f'{ctx.guild.get_member(dbutils.read("requests")[request]["fulfiller"]).name} ' \
                                f'at {dbutils.read("requests")[request]["timefulfilled"]}.'
            await ctx.send(embed=embed)
            return None

        await ctx.message.delete()

        if dbutils.read("requests")[request]["faction"] == 1:
            channel = discord.utils.get(
                ctx.guild.channels,
                id=int(dbutils.get_vault(ctx.guild.id, "banking")))
        else:
            channel = discord.utils.get(
                ctx.guild.channels,
                id=int(dbutils.get_vault(ctx.guild.id, "banking2")))
        original = await channel.fetch_message(
            int(dbutils.read("requests")[request]["requestmessage"]))

        embed = discord.Embed()
        embed.title = original.embeds[0].title

        channel = discord.utils.get(ctx.guild.channels,
                                    name=dbutils.get_vault(
                                        ctx.guild.id, "channel"))
        message = await channel.fetch_message(
            int(dbutils.read("requests")[request]["withdrawmessage"]))

        embed.add_field(name='Original Message',
                        value=message.embeds[0].description.split(".")[0])
        embed.description = f'The request has been fulfilled by {ctx.message.author.name} at {time.ctime()}.'
        await message.edit(embed=embed)

        embed.description = f'The request has been fulfilled by {ctx.message.author.name} at {time.ctime()}.'
        embed.clear_fields()
        await original.edit(embed=embed)

        data = dbutils.read("requests")
        data[request]["fulfiller"] = ctx.message.author.id
        data[request]["fulfilled"] = True
        data[request]["timefulfilled"] = time.ctime(),
        dbutils.write("requests", data)

        await asyncio.sleep(60)
        await original.delete()
コード例 #2
0
async def on_member_join(member):
    data = dbutils.read('users')

    if str(member.id) in data:
        return None
    if member.bot:
        return None
    data[member.id] = {
        "tornid": "",
        "tornapikey": "",
        "generaluse": False
    }
    dbutils.write("users", data)
コード例 #3
0
async def on_message(message):
    if message.author.bot:
        return None
    if str(message.channel.id) == dbutils.read("vault")[str(message.guild.id)]["banking"] \
            and message.clean_content[0] != get_prefix(client, message):
        await message.delete()
        embed = discord.Embed()
        embed.title = "Bot Channel"
        embed.description = "This channel is only for vault withdrawals. Please do not post any other messages in" \
                            " this channel."
        message = await message.channel.send(embed=embed)
        await asyncio.sleep(30)
        await message.delete()

    await bot.process_commands(message)
コード例 #4
0
import discord, asyncio, os, platform, sys
from discord.ext.commands import Bot
from discord.ext import commands
import dbutils

if not os.path.isfile("config.py"):
	sys.exit("'config.py' not found! Please add it and try again.")
else:
	import config

dbutils.initialize()

guilds = dbutils.read("guilds")
vaults = dbutils.read("vault")
users = dbutils.read("users")
aractions = dbutils.read("armory")

intents = discord.Intents.all()

bot = Bot(command_prefix=config.BOT_PREFIX, intents=intents)

@bot.event
async def on_ready():
  guild_count = 0

  for guild in bot.guilds:
    print(f"- {guild.id} (name: {guild.name})")
    guild_count +=1

    for jsonguild in guilds["guilds"]:
      if jsonguild["id"] == str(guild.id):
コード例 #5
0
def get_prefix(bot, message):
    for guild in dbutils.read("guilds")["guilds"]:
        if guild["id"] == str(message.guild.id):
            return guild["prefix"]
コード例 #6
0
ファイル: admin.py プロジェクト: ryanegenlangston1993/hrtrn
    async def config(self, ctx, arg=None, value=None):
        '''
        Returns the current configuration of the bot
        '''

        if not check_admin(ctx.message.author) and dbutils.get_superuser(
        ) != ctx.message.author.id:
            embed = discord.Embed()
            embed.title = "Permission Denied"
            embed.description = f'This command requires {ctx.message.author.name} to be an Administrator. ' \
                                f'This interaction has been logged.'
            await ctx.send(embed=embed)

            log(
                f'{ctx.message.author.name} has attempted to run config, but is not an Administrator',
                self.access)
            return None

        embed = discord.Embed()

        if not arg:
            embed = None
            page1 = discord.Embed(
                title="Configuration",
                description=f'''Torn API Key: Classified
                Bot Token: Classified
                Prefix: {get_prefix(self.bot, ctx.message)}
                Superuser: {dbutils.get_superuser()}''',
            ).set_footer(text="Page 1/2")
            page2 = discord.Embed(
                title="Configuration: Vault",
                description=
                f'''Vault Channel: {dbutils.read("vault")[str(ctx.guild.id)]["channel"]}
                Vault Channel 2: {dbutils.read("vault")[str(ctx.guild.id)]["channel2"]}
                Vault Role: {dbutils.read("vault")[str(ctx.guild.id)]["role"]}
                Vault Role 2: {dbutils.read("vault")[str(ctx.guild.id)]["role2"]}
                Banking Channel: {dbutils.read("vault")[str(ctx.guild.id)]["banking"]}
                Banking Channel 2: {dbutils.read("vault")[str(ctx.guild.id)]["banking2"]}'''
            ).set_footer(text="Page 2/2")

            pages = [page1, page2]

            message = await ctx.send(embed=page1)
            await message.add_reaction('⏮')
            await message.add_reaction('◀')
            await message.add_reaction('▶')
            await message.add_reaction('⏭')

            def check(reaction, user):
                return user == ctx.author

            i = 0
            reaction = None

            while True:
                if str(reaction) == '⏮':
                    i = 0
                    await message.edit(embed=pages[i])
                elif str(reaction) == '◀':
                    if i > 0:
                        i -= 1
                        await message.edit(embed=pages[i])
                elif str(reaction) == '▶':
                    if i < 2:
                        i += 1
                        await message.edit(embed=pages[i])
                elif str(reaction) == '⏭':
                    i = 2
                    await message.edit(embed=pages[i])

                try:
                    reaction, user = await self.bot.wait_for('reaction_add',
                                                             timeout=30.0,
                                                             check=check)
                    await message.remove_reaction(reaction, user)
                except:
                    break

            await message.clear_reactions()
        # Configurations that require a value below here
        elif not value:
            embed.title = "Value Error"
            embed.description = "A value must be passed"
        elif arg == "vc":
            for channel in ctx.guild.channels:
                if str(channel.id) != value[2:-1]:
                    continue
                data = dbutils.read("vault")
                data[str(ctx.guild.id)]["channel"] = channel.name
                dbutils.write("vault", data)
                log(
                    f'Vault Channel has been set to {data[str(ctx.guild.id)]["channel"]}.',
                    self.log_file)
                embed.title = "Vault Channel"
                embed.description = f'Vault Channel has been set to {data[str(ctx.guild.id)]["channel"]}.'
        elif arg == "vc2":
            for channel in ctx.guild.channels:
                if str(channel.id) != value[2:-1]:
                    continue
                data = dbutils.read("vault")
                data[str(ctx.guild.id)]["channel2"] = channel.name
                dbutils.write("vault", data)
                log(
                    f'Vault Channel 2 has been set to {data[str(ctx.guild.id)]["channel2"]}.',
                    self.log_file)
                embed.title = "Vault Channel 2"
                embed.description = f'Vault Channel 2 has been set to {data[str(ctx.guild.id)]["channel2"]}.'
        elif arg == "vr":
            for role in ctx.guild.roles:
                if role.mention != value:
                    continue
                data = dbutils.read("vault")
                data[str(ctx.guild.id)]["role"] = str(role.mention)
                dbutils.write("vault", data)
                log(
                    f'Vault Role has been set to {data[str(ctx.guild.id)]["role"]}.',
                    self.log_file)
                embed.title = "Vault Role"
                embed.description = f'Vault Role has been set to {data[str(ctx.guild.id)]["role"]}.'
        elif arg == "vr2":
            for role in ctx.guild.roles:
                if role.mention != value:
                    continue
                data = dbutils.read("vault")
                data[str(ctx.guild.id)]["role2"] = str(role.mention)
                dbutils.write("vault", data)
                log(
                    f'Vault Role has been set to {data[str(ctx.guild.id)]["role2"]}.',
                    self.log_file)
                embed.title = "Vault Role"
                embed.description = f'Vault Role has been set to {data[str(ctx.guild.id)]["role2"]}.'
        elif arg == "prefix":
            data = dbutils.read("guilds")

            for guild in data["guilds"]:
                if guild["id"] == str(ctx.guild.id):
                    guild["prefix"] = str(value)

            dbutils.write("guilds", data)
            log(f'Bot Prefix has been set to {value}.', self.log_file)
            embed.title = "Bot Prefix"
            embed.description = f'Bot Prefix has been set to {value}.'
        elif arg == "key":
            data = dbutils.read("guilds")

            for guild in data["guilds"]:
                if guild["id"] == str(ctx.guild.id):
                    guild["tornapikey"] = str(value)

            dbutils.write("guilds", data)
            log(f'{ctx.message.author.name} has set the primary Torn API Key.',
                self.log_file)
            embed.title = "Torn API Key"
            embed.description = f'The Torn API key for the primary faction has been set by {ctx.message.author.name}.'
            await ctx.message.delete()
        elif arg == "key2":
            data = dbutils.read("guilds")

            for guild in data["guilds"]:
                if guild["id"] == str(ctx.guild.id):
                    guild["tornapikey2"] = str(value)

            dbutils.write("guilds", data)
            log(
                f'{ctx.message.author.name} has set the secondary Torn API Key.',
                self.log_file)
            embed.title = "Torn API Key"
            embed.description = f'The Torn API key for the secondary faction has been set by {ctx.message.author.name}.'
            await ctx.message.delete()
        elif arg == "bc":
            for channel in ctx.guild.channels:
                if str(channel.id) != value[2:-1]:
                    continue
                data = dbutils.read("vault")
                data[str(ctx.guild.id)]["banking"] = str(channel.id)
                dbutils.write("vault", data)
                log(
                    f'Banking Channel has been set to {data[str(ctx.guild.id)]["banking"]}.',
                    self.log_file)
                embed.title = "Banking Channel"
                embed.description = f'Banking Channel has been set to {channel.name}.'
        elif arg == "bc2":
            for channel in ctx.guild.channels:
                if str(channel.id) != value[2:-1]:
                    continue
                data = dbutils.read("vault")
                data[str(ctx.guild.id)]["banking2"] = str(channel.id)
                dbutils.write("vault", data)
                log(
                    f'Banking Channel 2 has been set to {data[str(ctx.guild.id)]["banking2"]}.',
                    self.log_file)
                embed.title = "Banking Channel 2"
                embed.description = f'Banking Channel 2 has been set to {channel.name}.'
        else:
            embed.title = "Configuration"
            embed.description = "This key is not a valid configuration key."

        if embed is not None:
            await ctx.send(embed=embed)
コード例 #7
0
ファイル: tvault.py プロジェクト: ryanegenlangston1993/hrtrn
    async def withdraw(self, ctx, arg):
        '''
        Sends a message to faction leadership (assuming you have enough funds in the vault and you are a member of the
        specific faction)
        '''

        # sender = None
        if ctx.message.author.nick is None:
            sender = ctx.message.author.name
        else:
            sender = ctx.message.author.nick

        senderid = get_torn_id(sender)
        sender = remove_torn_id(sender)

        if dbutils.get_user(ctx.message.author.id, "tornid") == "":
            verification = await tornget(
                ctx,
                f'https://api.torn.com/user/{senderid}?selections=discord&key='
            )

            if verification["discord"]["discordID"] != str(ctx.message.author.id) and \
                    verification["discord"]["discordID"] != "":
                embed = discord.Embed()
                embed.title = "Permission Denied"
                embed.description = f'The nickname of {ctx.message.author.nick} in {ctx.guild.name} does not reflect ' \
                                    f'the Torn ID and username. Please update the nickname (i.e. through YATA) or add' \
                                    f' your ID to the database via the `?addid` or `addkey` commands (NOTE: the ' \
                                    f'`?addkey` command requires your Torn API key). This interaction has been logged.'
                await ctx.send(embed=embed)
                log(
                    f'{ctx.message.author.id} (known as {ctx.message.author.name} does not have an accurate nickname, '
                    f'and attempted to withdraw some money from the faction vault.',
                    self.access_file)
                return None

        value = text_to_num(arg)
        log(sender + " has submitted a request for " + arg + ".",
            self.log_file)

        primary_faction = await tornget(
            ctx, "https://api.torn.com/faction/?selections=&key=")

        secondary_faction = None
        if dbutils.get_guild(ctx.guild.id, "tornapikey2") != "":
            secondary_faction = await tornget(
                ctx,
                "https://api.torn.com/faction/?selections=&key=",
                guildkey=2)

        await ctx.message.delete()

        if senderid in primary_faction["members"]:
            request = await tornget(
                ctx, "https://api.torn.com/faction/?selections=donations&key=")
            request = request["donations"]

            if int(value) > request[senderid]["money_balance"]:
                log(
                    f'{sender} has requested {arg}, but only has {request[senderid]["money_balance"]} in '
                    f'the vault.', self.log_file)
                await ctx.send(f'You do not have {arg} in the faction vault.')
                return None
            else:
                channel = discord.utils.get(ctx.guild.channels,
                                            name=dbutils.get_vault(
                                                ctx.guild.id, "channel"))

                log(
                    f'{sender} has successfully requested {arg} from the faction vault.',
                    self.log_file)

                requestid = dbutils.read("requests")["nextrequest"]

                embed = discord.Embed()
                embed.title = f'Money Request #{dbutils.read("requests")["nextrequest"]}'
                embed.description = "Your request has been forwarded to the faction leadership."
                original = await ctx.send(embed=embed)

                embed = discord.Embed()
                embed.title = f'Money Request #{dbutils.read("requests")["nextrequest"]}'
                embed.description = f'{sender} is requesting {arg} from the faction vault. To fulfill this request, ' \
                                    f'enter `?f {requestid}` in this channel.'
                message = await channel.send(dbutils.get_vault(
                    ctx.guild.id, "role"),
                                             embed=embed)

                data = dbutils.read("requests")
                data["nextrequest"] += 1
                data[requestid] = {
                    "requester": ctx.message.author.id,
                    "timerequested": time.ctime(),
                    "fulfiller": None,
                    "timefulfilled": "",
                    "requestmessage": original.id,
                    "withdrawmessage": message.id,
                    "fulfilled": False,
                    "faction": 1
                }
                dbutils.write("requests", data)

        elif senderid in secondary_faction["members"]:
            request = await tornget(
                ctx,
                "https://api.torn.com/faction?selections=donations&key=",
                guildkey=2)
            request = request["donations"]

            if int(value) > request[senderid]["money_balance"]:
                log(
                    f'{sender} has requested {arg}, but only has {request[senderid]["money_balance"]} in '
                    f'the vault.', self.log_file)
                await ctx.send(f'You do not have {arg} in the faction vault.')
                return None
            else:
                channel = discord.utils.get(ctx.guild.channels,
                                            name=dbutils.get_vault(
                                                ctx.guild.id, "channel2"))

                log(
                    f'{sender} has successfully requested {arg} from the faction vault.',
                    self.log_file)

                requestid = dbutils.read("requests")["nextrequest"]

                embed = discord.Embed()
                embed.title = f'Money Request #{dbutils.read("requests")["nextrequest"]}'
                embed.description = "Your request has been forwarded to the faction leadership."
                original = await ctx.send(embed=embed)

                embed = discord.Embed()
                embed.title = f'Money Request #{dbutils.read("requests")["nextrequest"]}'
                embed.description = f'{sender} is requesting {arg} from the faction vault. To fulfill this request, ' \
                                    f'enter `?f {requestid}` in this channel.'
                message = await channel.send(dbutils.get_vault(
                    ctx.guild.id, "role"),
                                             embed=embed)

                data = dbutils.read("requests")
                data["nextrequest"] += 1
                data[requestid] = {
                    "requester": ctx.message.author.id,
                    "timerequested": time.ctime(),
                    "fulfiller": None,
                    "timefulfilled": "",
                    "requestmessage": original.id,
                    "withdrawmessage": message.id,
                    "fulfilled": False,
                    "faction": 2
                }
                dbutils.write("requests", data)
        else:
            log(
                f'{sender} who is not a member of stored factions has requested {arg}.',
                self.log_file)

            embed = discord.Embed()
            embed.title = "Money Request"
            embed.description = f'{sender} is not a member of stored factions has requested {arg}.'
            await ctx.send(embed=embed)
            return None