async def on_ready():
    for guild in bot.guilds:
        logger.info(
            f'Logged into server: "{guild.name}" (id: {guild.id}, members: {guild.member_count})'
        )
    await bot.change_presence(
        activity=disnake.Activity(type=disnake.ActivityType.listening,
                                  name=f"!{bot_command_prefix} help"))
Exemple #2
0
    async def set(self, ctx, status: disnake.Status, type_: activity_type,
                  name: str):
        """Set a custom presence"""
        self.update_presence.cancel()

        await self.bot.change_presence(status=status,
                                       activity=disnake.Activity(type=type_,
                                                                 name=name))
Exemple #3
0
    async def reload_cogs_on_change(self):
        try:
            await self.bot.wait_until_ready()
            await self.bot.change_presence(
                status=disnake.Status.dnd,
                activity=disnake.Activity(type=disnake.ActivityType.watching,
                                          name="for changes [dev]"))

            async for changes in awatch('cogs'):
                for change in changes:
                    file = change[1]
                    st = await stat(file)
                    if st.st_size == 0:
                        continue

                    if len(file.split('/')) == 2:
                        module = os.path.splitext(file)[0].replace('/', '.')
                        self.log.info(f'Module {module} changed')
                        try:
                            self.bot.reload_extension(module)

                        except commands.ExtensionNotLoaded:
                            pass

                        except commands.ExtensionError as e:
                            await self.bot.stats_webhook.send(
                                f'{e.__class__.__name__}: {e}')
                            traceback.print_exc()

                        else:
                            await self.bot.change_presence(
                                status=disnake.Status.online,
                                activity=disnake.Activity(
                                    type=disnake.ActivityType.playing,
                                    name=f"reloaded {module} [dev]"))

        except Exception as e:
            self.log.error(e)
            traceback.print_exc()
Exemple #4
0
 async def setstatus(self, ctx, type:int, *, status:str):
     """Sets a playing/streaming/listening/watching status"""
     await self.bot.change_presence(activity=disnake.Activity(name=status, type=type))
     await ctx.send("Status updated")
Exemple #5
0
 def sample_text(self) -> disnake.Activity:
     return disnake.Activity(
         type=disnake.ActivityType.playing,
         name=
         "s͍͇̥̟̗̰͓̋̌ͤ̏̋͂̎ḁ͙̣̝͎̏ͪ̎͋ͅm̖͗ͯ̀̊p̥͇̳̜̬̫͇̒͋̓l̪̪̃̒̄͐̓̆e͉̼̤̬͎͔̞ͯͅ ̰̦̻̭̑̄̈́ͤt̳̘̫ͧͤͬ͌́ͦe̗̳̤͖̞ͣ̏͊̒ͪͅx͕͕̔͆̃̍ͫ͆t̗̤ͭͣ̒͑͆͋ͬ͒͊"
     )
Exemple #6
0
 def apocalypse(self) -> disnake.Activity:
     return disnake.Activity(type=disnake.ActivityType.streaming,
                             name="the apocalypse",
                             url="https://twitch.tv//")
Exemple #7
0
 def question(self) -> disnake.Activity:
     return disnake.Activity(type=disnake.ActivityType.playing,
                             name="????-???????????? ??")
Exemple #8
0
 def baguette(self) -> disnake.Activity:
     return disnake.Activity(type=disnake.ActivityType.listening,
                             name="baguette \N{BAGUETTE BREAD}")
Exemple #9
0
 def world_burn(self) -> disnake.Activity:
     return disnake.Activity(type=disnake.ActivityType.watching,
                             name="the world burn")
Exemple #10
0
 def default(self) -> disnake.Activity:
     return disnake.Activity(
         type=disnake.ActivityType.watching,
         name=
         f"{sum([g.member_count for g in self.bot.guilds]):,} humans in {len(list(self.bot.guilds)):,} guilds"
     )
@app.get("/")
async def read_root():
    return {"Hello": str(gst_bot.user)}


@app.post("/")
async def write_root(request: Request):
    # TODO: Make this work for more bots
    req_info = await request.body()
    value = handle_groupme(req_info)
    return {"Worked": value}


activity = disnake.Activity(
    type=disnake.ActivityType.watching,
    name="Gamestonk Terminal: https://github.com/GamestonkTerminal/GamestonkTerminal",
)


def fancy_traceback(exc: Exception) -> str:
    """May not fit the message content limit"""
    text = "".join(traceback.format_exception(type(exc), exc, exc.__traceback__))
    return f"```py\n{text[-4086:]}\n```"


class GSTHelpCommand(commands.MinimalHelpCommand):
    """Custom Help Command."""

    def get_command_signature(self, command):
        command_syntax = f"{self.clean_prefix}{command.qualified_name}"
        command_usage = command.usage if command.usage is not None else ""
Exemple #12
0
import os
import re
import random

import disnake
from pathlib import Path
from pymongo import MongoClient
from disnake.ext import commands
from disnake.utils import get

client = commands.Bot(command_prefix=commands.when_mentioned_or('cy/'),
                      intents=disnake.Intents.all(),
                      owner_id=338714886001524737,
                      status=disnake.Status.idle,
                      activity=disnake.Activity(
                          type=disnake.ActivityType.watching,
                          name='Чё там у хохлов'),
                      allowed_mentions=disnake.AllowedMentions(everyone=False),
                      case_insensitive=True)
client.remove_command('help')
passw = os.environ.get('passw')
cluster = MongoClient(
    f"mongodb+srv://cephalon:{passw}@locale.ttokw.mongodb.net/Locale?retryWrites=true&w=majority"
)
collection = cluster.Locale.locale
cwd = Path(__file__).parents[0]
cwd = str(cwd)


@client.event
async def on_ready():
Exemple #13
0
class OBSBot(commands.Bot):
    def __init__(self, config_file):
        intents = disnake.Intents(bans=True,
                                  emojis=True,
                                  guilds=True,
                                  members=True,
                                  messages=True,
                                  reactions=True,
                                  voice_states=False)
        super().__init__(command_prefix='.',
                         help_command=None,
                         intents=intents)  # type: ignore

        self.config = toml.load(open(config_file))
        self.state = StateFile(self.config['bot']['state_file'])
        self.db = DBHelper()
        self.loop.run_until_complete(self.db.connect(self.config['db']))

        timeout = aiohttp.ClientTimeout(total=60)
        self.session = aiohttp.ClientSession(loop=self.loop, timeout=timeout)

        # load cogs
        for module in public_cogs:
            logger.info(f'Loading public extension: {module}')
            self.load_extension('obsbot.cogs.public.' + module)
        for module in private_cogs:
            logger.info(f'Loading private extension: {module}')
            self.load_extension('obsbot.cogs.private.' + module)

        # set by on_ready
        self.start_time = None
        self.main_guild = None
        self.supporter_role = None
        self.contrib_role = None
        # admin ids, set via config, but can be changed at runtime
        self.admins = set(self.config['bot']['admins'])
        self.admins.add(self.config['bot']['owner'])
        self.supporters = set()
        self.contributors = set()

    async def on_ready(self):
        logger.info('OBS Bot ready!')
        logger.info(f'Name: {self.user} (ID: {self.user.id})')

        self.start_time = time.time()
        self.main_guild = self.get_guild(self.config['bot']['main_guild'])
        self.supporter_role = self.main_guild.get_role(
            self.config['bot']['supporter_role'])
        if self.supporter_role:
            for user in self.supporter_role.members:
                self.supporters.add(user.id)
        self.contrib_role = self.main_guild.get_role(
            self.config['bot']['contributor_role'])
        if self.contrib_role:
            for user in self.contrib_role.members:
                self.contributors.add(user.id)

        if game := self.state.get('game', None):
            activity = disnake.Game(game)
        elif song := self.state.get('song', None):
            activity = disnake.Activity(name=song,
                                        type=disnake.ActivityType.listening)
Exemple #14
0
        if self.supporter_role:
            for user in self.supporter_role.members:
                self.supporters.add(user.id)
        self.contrib_role = self.main_guild.get_role(
            self.config['bot']['contributor_role'])
        if self.contrib_role:
            for user in self.contrib_role.members:
                self.contributors.add(user.id)

        if game := self.state.get('game', None):
            activity = disnake.Game(game)
        elif song := self.state.get('song', None):
            activity = disnake.Activity(name=song,
                                        type=disnake.ActivityType.listening)
        else:
            activity = disnake.Activity(name='your problems',
                                        type=disnake.ActivityType.listening)

        await self.change_presence(activity=activity)

    def is_admin(self, user: disnake.Member):
        if user.id in self.admins:
            return True
        return False

    def is_supporter(self, user: disnake.Member):
        if self.is_admin(user):
            return True
        elif user.id in self.supporters:
            return True
        return False