Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord, asyncio, aiohttp, json, time, datetime, pickle, os.path, re, traceback, COC, sys, time
- from discord.ext import commands, tasks
- from tinydb import TinyDB, Query, where
- import logging
- logger = logging.getLogger('discord')
- logger.setLevel(logging.ERROR)
- handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w')
- handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
- logger.addHandler(handler)
- home_coc_token = """REDACTED"""
- clan_DB = TinyDB('clan_database.json')
- bot_DB = TinyDB('bot_database.json')
- url = "https://api.clashofclans.com/v1/"
- params = None
- headers = {
- 'Accept': "application/json",
- 'Authorization': "Bearer " + home_coc_token
- }
- SCOPES = [REDACTED]
- class AdminCog(commands.Cog,command_attrs=dict(hidden=False)):#name="Admin",
- def __init__(self,bot):
- self.bot = bot
- async def cog_check(self, ctx):
- return ctx.author.id == 148319665188372481
- @commands.command()
- async def calendar(self, ctx, new_cal_id : str):
- """Changes calendar ID."""
- id_str = Query()
- bot_DB.update({'calendar_id': new_cal_id}, id_str.calendar_id)
- await ctx.send('Changed calendar id.')
- @commands.command()
- async def reload(self, ctx, extension_name : str):
- """Reloads an extension."""
- try:
- self.bot.unload_extension(extension_name)
- self.bot.load_extension(extension_name)
- except (AttributeError, ImportError) as e:
- await ctx.message.channel.send("```py\n{}: {}\n```".format(type(e).__name__, str(e)))
- return
- await ctx.message.channel.send("{} loaded.".format(extension_name))
- @commands.command()
- async def add_extension(self, ctx, extension_name : str):
- """Adds an extension to be automatically loaded at bot start."""
- record = bot_DB.search(where('server_id') == 321963490111913987)
- extension_list = record[0]['extensions']
- extension_list.append(extension_name)
- bot_DB.update({'extensions': extension_list}, where('server_id') == 321963490111913987)
- await ctx.message.channel.send(f"{extension_name} added to list.")
- @commands.command()
- async def remove_extension(self, ctx, extension_name : str = None):
- """Removes an extension to be automatically loaded at bot start."""
- record = bot_DB.search(where('server_id') == 321963490111913987)
- extension_list = record[0]['extensions']
- if extension_name == None: await ctx.message.channel.send(f'The current extensions are: {extension_list}')
- else:
- try:
- extension_list.remove(extension_name)
- bot_DB.update({'extensions': extension_list}, where('server_id') == 321963490111913987)
- await ctx.message.channel.send(f"{extension_name} removed from list.")
- except:
- await ctx.message.channel.send(f'There was an error, the current extensions are: {extension_list}')
- @commands.command() #adds a new clan to the clan_db database
- async def addclan(self, ctx, clantag, channel: discord.TextChannel, role: discord.Role):
- clan_url = f'{url}clans/%23{clantag}'
- async with aiohttp.ClientSession() as session:
- async with session.get(clan_url, params = params, headers=headers) as r:
- if r.status == 200:
- resp = await r.json()
- clan_DB.upsert({'name': resp['name'],
- 'clantag': resp['tag'],
- 'channel': channel.id,
- 'role': role.id,
- 'current_war': {'startTime': None,
- 'endTime': None,
- 'members': None},
- 'past_war': {'startTime': None,
- 'endTime': None,
- 'members': None}},
- )
- await ctx.channel.send(f'Successfully added {resp["name"]} to the database!')
- else: await ctx.channel.send('There was an error, check log for details.')
- def setup(bot):
- bot.add_cog(AdminCog(bot))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement