Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.10 KB | None | 0 0
  1. import json
  2. from datetime import datetime
  3. from os import path, listdir
  4. from discord.ext.commands import Bot, when_mentioned_or
  5. from discord import DMChannel
  6. from aiohttp import ClientSession
  7.  
  8. from orchidbot.cogs import linkblock
  9.  
  10.  
  11. class Orchid(Bot):
  12.     def __init__(self, *args, **options):
  13.         super().__init__(*args, **options)
  14.         self.session = None
  15.         with open('../config.json') as configfile:
  16.             self.config = json.load(configfile)
  17.         self.last_errors = []
  18.  
  19.     async def start(self, *args, **kwargs):
  20.         self.session = ClientSession()
  21.         await super().start(self.config["bot_key"], *args, **kwargs)
  22.  
  23.     async def close(self):
  24.         await self.session.close()
  25.         await super().close()
  26.  
  27.     def user_is_admin(self, user):
  28.         try:
  29.             user_roles = [role.id for role in user.roles]
  30.         except AttributeError:
  31.             return False
  32.         permitted_roles = self.config['admin_roles']
  33.         return any(role in permitted_roles for role in user_roles)
  34.  
  35.     def user_is_superuser(self, user):
  36.         superusers = self.config['superusers']
  37.         return user.id in superusers
  38.  
  39.     def user_is_ignored(self, user):
  40.         user_roles = [role.id for role in user.roles]
  41.         if self.config['ignore_role'] in user_roles:
  42.             return True
  43.         return False
  44.  
  45.  
  46. client = Orchid(
  47.     command_prefix=when_mentioned_or('orchid ', 'Orchid '),
  48.     description='Hi I\'m Orchid!',
  49.     max_messages=15000
  50. )
  51.  
  52.  
  53. @client.event
  54. async def on_ready():
  55.     main_id = client.config['main_guild']
  56.     client.main_guild = client.get_guild(main_id) or client.guilds[0]
  57.     print('\nActive in these guilds/servers:')
  58.     [print(g.name) for g in client.guilds]
  59.     print('\nMain guild:', client.main_guild.name)
  60.     print('\nOrchid started successfully')
  61.     return True
  62.  
  63.  
  64. @client.event
  65. async def on_message(message):
  66.     if isinstance(message.channel, DMChannel):
  67.         return
  68.     if client.user_is_ignored(message.author):
  69.         return
  70.     await client.process_commands(message)
  71.  
  72.  
  73. client.run()
  74. print('Orchid has exited')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement