Пример #1
0
 def __init__(self):
     """Regular init"""
     super().__init__(
         command_prefix=self.get_prefix,
         pm_help=None,
         allowed_mentions=discord.AllowedMentions(
             users=True,
             roles=False,
             everyone=False
         ),
         case_insensitive=True,
         status=discord.Status.online,
         intents=discord.Intents.all()
     )
     self.colour = 0x00dcff
     self.prefixes, self._tag_dict, self.global_votes = {}, {}, {}
     self.config = _cyber.config()
     self.logger = _cyber.logger()
     self.start_time = dt.utcnow()
     self.ext = [f"CyberTron5000.cogs.{filename[:-3]}" for filename in os.listdir('./cogs') if
                 filename.endswith('.py')]
     self.clever = Cleverbot(self.config.cleverbot)
     self.clever.set_context(DictContext(self))
     self.load_extension(name='jishaku')
     self.loop.create_task(self.__aioinit__())
     self.embed = CyberEmbed
     self.colour_chooser = CyberColours
Пример #2
0
    def __init__(self, bot):
        self.bot = bot
        self.chatting = []

        self.chatbot = Cleverbot(os.getenv("CLEVERBOT"), context=DictContext())
Пример #3
0
class CyberTron5000(Bot):
    def __init__(self):
        """Regular init"""
        super().__init__(
            command_prefix=self.get_prefix,
            pm_help=None,
            allowed_mentions=discord.AllowedMentions(
                users=True,
                roles=False,
                everyone=False
            ),
            case_insensitive=True,
            status=discord.Status.online,
            intents=discord.Intents.all()
        )
        self.colour = 0x00dcff
        self.prefixes, self._tag_dict, self.global_votes = {}, {}, {}
        self.config = _cyber.config()
        self.logger = _cyber.logger()
        self.start_time = dt.utcnow()
        self.ext = [f"CyberTron5000.cogs.{filename[:-3]}" for filename in os.listdir('./cogs') if
                    filename.endswith('.py')]
        self.clever = Cleverbot(self.config.cleverbot)
        self.clever.set_context(DictContext(self))
        self.load_extension(name='jishaku')
        self.loop.create_task(self.__aioinit__())
        self.embed = CyberEmbed
        self.colour_chooser = CyberColours

    async def __aioinit__(self):
        """Async init"""
        self.db = await asyncpg.create_pool(**self.config.pg_data)
        self.session = aiohttp.ClientSession()
        await self.startup()

    @property
    def owner(self) -> discord.User:
        return self.get_user(350349365937700864)  # me

    @property
    def logging_channel(self) -> List[discord.TextChannel]:
        return [self.get_channel(727277234666078220), self.get_channel(746935543144644650),
                self.get_channel(746935661201981510)]

    def run(self, *args, **kwargs):
        super().run(self.config.bot_token)

    @property
    def uptime(self) -> dict:
        delta_uptime = dt.utcnow() - self.start_time
        hours, remainder = divmod(int(delta_uptime.total_seconds()), 3600)
        minutes, seconds = divmod(remainder, 60)
        days, hours = divmod(hours, 24)
        return {'days': days, 'hours': hours, 'minutes': minutes, 'seconds': seconds}

    async def get_prefix(self, message):
        if not message.guild:
            return 'c$'
        DEFAULT_PREFIX = ["c$"]
        prefixes = self.prefixes.get(message.guild.id, DEFAULT_PREFIX)
        if message.author.id == self.owner.id:
            return when_mentioned_or(*prefixes, 'dev ')(self, message)
        return when_mentioned_or(*prefixes)(self, message)

    async def get_context(self, message, *, cls=None):
        return await super().get_context(message, cls=cls or _cyber.CyberContext)

    async def startup(self):
        await self.wait_until_ready()
        print(f"{self.user.name.upper()} IS ONLINE")
        for file in self.ext:
            try:
                self.load_extension(name=file)
            except Exception as error:
                print(f"Could not load {file}: {error}")
        print(f"COGS HAVE BEEN LOADED")
        prefix_data = await self.db.fetch("SELECT guild_id, array_agg(prefix) FROM prefixes GROUP BY guild_id")
        for entry in prefix_data:
            self.prefixes[entry['guild_id']] = entry['array_agg']
        await self.change_presence(activity=discord.Activity(type=discord.ActivityType.watching,
                                                             name=f"{len(self.users):,} users in {len(self.guilds):,} guilds"))
        print("PREFIXES AND PRESENCE SETUP")
        SQL = """
        SELECT guild_id FROM tags
        """
        tags = await self.db.fetch(SQL)
        for query in tags:
            self._tag_dict[query['guild_id']] = {}
            SQL2 = """
            SELECT name, content, uses, user_id, id FROM tags WHERE guild_id = $1;
            """
            tags2 = await self.db.fetch(SQL2, query['guild_id'])
            for query2 in tags2:
                self._tag_dict[query['guild_id']][query2['name'].lower()] = \
                    {
                        'content': query2['content'],
                        'uses': query2['uses'] or 0,
                        'author': query2['user_id'],
                        'id': query2['id']
                    }
        print("TAGS HAVE BEEN INITIALIZED")
        print("READY!")
        print("───────────────────────────────────────────────────────────────────────────────────────────────────────")