Exemplo n.º 1
0
    async def on_message_edit(self, before, after):
        #  b_m = before.content.lower()
        a_m = after.content.lower()

        # go ahead and check which server we're in
        is_tdt = False
        #  is_neon = False
        #  is_durg = False
        try:
            is_tdt = str(after.guild.id) == private.tdt_server_id
        except AttributeError as e:
            debug.debug(
                debug.D_ERROR,
                'Caught AttributeError while trying to determine what server a message came from. {}'
                .format(e))

        # handle sneaky no_words
        for regex in strings.no_words_regex:
            if re.search(regex, a_m):
                debug.debug(
                    debug.D_INFO,
                    'A unacceptable word was used... attemting to delete it.')
                await send.message(after.channel, 'Noooo... nice try though.')

        # handle edited tdt commands
        if is_tdt:
            await tdt.handle_message(client, after)
Exemplo n.º 2
0
def read_points(client, message):
    id = 'null'
    pearlpoints = 0
    response = ''
    for mention in message.mentions:
        if mention != client.user:
            id = mention.id

            try:
                pearlpoints = int(
                    storage.get_user_attribute(message.guild.id, id,
                                               "pearl_points"))
            except KeyError as e:
                debug.debug(
                    debug.D_ERROR,
                    '{} did not have a \'pearl_points\' attribute.'.format(
                        mention))
                storage.set_user_attribute(message.guild.id, id,
                                           "pearl_points", pearlpoints)
                pearlpoints = int(
                    storage.get_user_attribute(message.guild.id, id,
                                               "pearl_points"))
            finally:
                if pearlpoints == 1:
                    response = "{} has {} pearl point.".format(
                        mention.mention, pearlpoints)
                else:
                    response = "{} has {} pearl points.".format(
                        mention.mention, pearlpoints)
        return response
Exemplo n.º 3
0
async def daily():
    #ensure that the timer is reset
    x = datetime.today()  # today
    if datetime.now().hour < 17:
        y = x.replace(hour=17, minute=0, second=0,
                      microsecond=0)  # today at 5pm
    else:
        if x.day + 1 <= calendar.monthrange(x.year, x.month)[1]:
            y = x.replace(day=x.day + 1,
                          hour=17,
                          minute=0,
                          second=0,
                          microsecond=0)  # tomorrow at 5pm
        else:
            if x.month + 1 <= 12:
                #  first day of next month at 5pm
                y = x.replace(month=x.month + 1,
                              day=1,
                              hour=17,
                              minute=0,
                              second=0,
                              microsecond=0)
            else:
                y = x.replace(year=x.year + 1,
                              month=1,
                              day=1,
                              hour=17,
                              minute=0,
                              second=0,
                              microsecond=0)

    delta_t = y - x  # time between now and next reset
    secs = delta_t.seconds + 1

    # t = Timer(secs, resetPointsToGive(server))

    # Fetch the current info before it's actually changed. This is important.
    _now = datetime.now()
    try:
        _next = parser.parse(storage.load_bot_setting('next_daily_datetime'))
    except storage.NoSuchSettingException:
        log.info('No daily reset time has been saved, yet.')
    # Now set the next reset to avoid this line running again.
    storage.save_bot_setting('next_daily_datetime', y)

    debug.debug(
        debug.D_VOMIT,
        'Current time: {} Next reset: {}'.format(_now.strftime('%H:%M:%S'),
                                                 _next.strftime('%H:%M:%S')))
    # Now do the stuff.
    if _now > _next:
        # DO DAILY STUFF HERE
        # TODO: Maybe put a method here and close this block as a helper to simplify readability.
        await tdt.daily()
Exemplo n.º 4
0
def read_points_to_give(client, message):
    id = 'null'
    pearlpointstogive = 0
    response = '... nothing happened ...'
    for mention in message.mentions:
        id = message.author.id

        try:
            pearlpointstogive = int(
                storage.get_user_attribute(message.guild.id, id,
                                           'available_pearl_points'))
        except KeyError as e:
            debug.debug(debug.D_ERROR, e)
        if pearlpointstogive == 1:
            response = "You have {} pearl point to give.".format(
                pearlpointstogive)
        else:
            response = "You have {} pearl points to give.".format(
                pearlpointstogive)
    return response
Exemplo n.º 5
0
async def catch_up(client):
    # channel_histories = []
    debug.debug(debug.D_INFO, 'Getting history for TDT...')
    msg_datetime = parser.parse(LAST_MESSAGE_TIME)
    for channel in _guild.text_channels:
        debug.debug(debug.D_INFO, 'Collecting messages from {}'.format(channel.name))
        try:
            messages = await channel.history(after=msg_datetime).flatten()
            for msg in messages:
                await handle_message(client, msg, False, True)
                print(msg.content)
                for mention in msg.mentions:
                    print(mention)
        except discord.errors.Forbidden as e:
            debug.debug(debug.D_INFO, "I don't have permission for {}.".format(channel.name))
Exemplo n.º 6
0
async def handle_message(client: discord.Client, message: discord.message, TALKATIVE: bool, CATCHUP = False):
    global update_loop
    global LAST_MESSAGE_TIME
    debug.debug(debug.D_VERBOSE, 'Entering TDT module.')

    LAST_MESSAGE_TIME = message.created_at

    # Cache the last message time so we can see where we're at later.
    if not CATCHUP:
        log.info('_guild.id = ' + str(_guild.id))
        log.info('LAST_MESSAGE_TIME = ' + str(LAST_MESSAGE_TIME))
        storage.set_server_attribute(_guild.id, 'last_message', LAST_MESSAGE_TIME)

    m = message.content.lower()

    # Liz's request for !wotd
    if '!wotd' in m:
        await wotd(message.channel)

    if '!wotd_raw' in m:
        await wotd(message.channel, True)

    # respond to solo fractal emote and give daily fractals
    if '<:fractals:230520375396532224>' in m and not CATCHUP:
        response = compose_fractal_response()
        await send.message(message.channel, response)
        # handled = True

    # Add reactions to some messages

    # Treebs was here...
    if 'treebs' in m or 'omega' in m or 'leftovers' in m and TALKATIVE:
        debug.debug(debug.D_INFO, 'Treebs was here...')
        await send.reaction(message, 'treebs:235655554465398784')

    # Plant the flag...
    if re.search('\\bgay(\\b|s)|\\bga{2,99}y(\\b|s)|\\blgbt\\b', m):
        debug.debug(debug.D_INFO, 'Someone said gay. Placing our flag.')
        try:
            # TODO: Something better than this? Why does this work?
            # It says it doesn't work, but it does exactly what I want it to.
            # I am confusion.
            await send.reaction(message, '🏳️‍🌈')
        except discord.errors.HTTPException as e:
            debug.debug(debug.D_ERROR, e)

    # End adding reactions

    # direct mention commands

    for mention in message.mentions:  # when someone is mentioned
        debug.debug(debug.D_VERBOSE, '{} was mentioned'.format(mention))
        if mention == client.user:  # if the bot is mentioned
            debug.debug(debug.D_VERBOSE, 'A mention other than the bot was caught.')
            # handled = False
            response = ''

            # -- pearl points --

            if ('give' in m or '+1' in m) and ('pearlpoint' in m or 'pearl point' in m or (
                    'pearl' in m and 'point' in m) or 'point' in m) and '!resetpointstogive' not in m and (
                    'do i' not in m):
                debug.debug(debug.D_VERBOSE, 'Pearl points are being given.')
                response = scoreboard.give_points(client, message)
            elif ('take' in m or 'remove' in m or '-1' in m) and (
                            'pearlpoint' in m or 'pearl point' in m or ('pearl' in m and 'point' in m) or 'point' in m):
                response = scoreboard.take_points(client, message)
            elif 'how many points' in m or 'how many pearlpoints' in m or (
                        'how' in m and 'many' in m and 'points' in m):
                if ' i ' in m:
                    debug.debug(debug.D_INFO, 'Fetching remaining points for {}.'.format(message.author))
                    response = scoreboard.read_points_to_give(client, message)
                else:
                    response = scoreboard.read_points(client, message)
            elif 'who\'s winning' in m or 'leaderboard' in m or 'scoreboard' in m:
                if 'beta' not in m:
                    response = scoreboard.get_top_points()
                elif 'beta' in m:
                    await send.message(message.channel, embed=scoreboard.get_top_points(True))
            debug.debug(debug.D_VERBOSE, '{}, {}'.format(message.author.id, private.anaeon_id))

            # -- end pearl points --

            # -- dailies --

            if re.search('\\bfractal(\\b|s)|\\bfric frac(\\b|s)', m) and not CATCHUP:
                response = compose_fractal_response()
                # await send.message(message.channel, response)
                # handled = True

            # -- end dailies --

            # -- general commands --

            # -- end general commands --

            # commands unique to myself
            if message.author.id == private.anaeon_id:
                if '!resetpearlpoints' in m:
                    response = scoreboard.reset_points(client, message)
                    # handled = True
                if '!initpearlpoints' in m:
                    response = scoreboard.init_points_to_give(message)
                    # handled = True
                if '!resetpointstogive' in m:  # forces daily-like reset.
                    response = scoreboard.reset_points_to_give(message.guild)
                    # handled = True
                if '!changeattribute' in m:  # @Ana !changeattribute @user attribute_name value
                    args = m.split(' ')
                    response = scoreboard.force_change_attribute(client, message, args[3].strip(), args[4].strip())
                    # handled = True
                if '!let' in m:
                    await send.message(message.channel, 'This command is broken. Please update.')
                    # await send.message(message.channel, embed = scoreboard.get_top_points(use_embed = True))

            if response != '':
                await send.message(message.channel, response)
Exemplo n.º 7
0
async def on_ready(client, loop):
    """
    Called when we're ready to start tasks from TDT's module.
    :param client: the client from the main module that called this.
    :type client: discord.Client()
    :param loop: The loop we're going to tie TDT's update loop to.
    :type loop: asyncio.AbstractEventLoop()
    """

    debug.debug(debug.D_INFO, 'Initializing TDT+ module.')

    global _gen_channel
    global _bot_channel
    global _guild
    global update_loop
    global LAST_MESSAGE_TIME

    debug.debug(debug.D_INFO, 'Collecting server info...')
    for server in client.guilds:
        debug.debug(debug.D_INFO, '{}:{} == {}'.format(
            server.id, private.tdt_server_id, server.id == private.tdt_server_id))
        if server.id == private.tdt_server_id:
            _guild = server
            debug.debug(debug.D_INFO, 'Server locked in...\nFinding channels...')
            for channel in server.text_channels:
                debug.debug(debug.D_INFO, 'Scanning channels...   ' + channel.name)
                if channel.name == 'general':
                    _gen_channel = channel
                    debug.debug(debug.D_INFO, 'General channel locked in...')
                elif channel.name == 'bot-test-chat':
                    _bot_channel = channel
                    debug.debug(debug.D_INFO, 'Bot channel locked in...')
    # update_loop = asyncio.run_coroutine_threadsafe(update(), loop=loop)
    if _gen_channel is not None and _bot_channel is not None and _guild is not None:
        debug.debug(debug.D_INFO, 'TDT+ initialized')
    else:
        debug.debug(debug.D_ERROR, 'TDT+ did not fully initialize...')
        if _guild is None:
            debug.debug(debug.D_ERROR, 'Couldn\'t lock in the server.')
        if _gen_channel is None:
            debug.debug(debug.D_ERROR, 'Couldn\'t find the general channel.')
        if _bot_channel is None:
            debug.debug(debug.D_ERROR, 'Couldn\'t find the bot channel.')

    # Time to catch up.
    LAST_MESSAGE_TIME = storage.get_server_attribute(_guild.id, 'last_message')
    await catch_up(client)
Exemplo n.º 8
0
    async def on_message(
            self, message
    ):  # when someone sends a message. Read command inputs here.
        m_guild = 'Unknown'
        m_channel = 'Unknown'
        if message.guild is not None:
            m_guild = str(message.guild)

        if message.channel is not None:
            m_channel = str(message.channel)

        debug.debug(
            debug.D_INFO,
            '[{}][{}][{}]:{}'.format(m_guild, m_channel, message.author,
                                     message.content))

        # go ahead and check which server we're in
        is_tdt = False
        is_neon = False
        is_durg = False
        try:
            is_tdt = str(message.guild.id) == private.tdt_server_id
        except AttributeError as e:
            debug.debug(debug.D_ERROR, 'AttributeError caught: {}'.format(e))

        m = message.content.lower()
        if message.author != client.user:  # don't react to your own messages.

            # Do these things in general...

            # get a random Trump quote because why the f**k not?

            if re.search('\\btrump\\b|\\bgyna\\b', m):
                await send.typing(message.channel)
                msg = trump.get_quote()
                await send.message(
                    message.channel,
                    '"{}" - Lord Emperor The Donald Trump'.format(msg))

            # end trump

            if re.search('\\broll\\b', m):
                sm = m.replace(' ', '')
                if re.search('d\d+', sm):
                    try:
                        roll = re.search('(?<=roll)*\d+d\d+', sm).group(0)
                    except:
                        roll = re.search('(?<=roll)*d\d+', sm).group(0)
                        pass
                    debug.debug(debug.D_INFO, 'roll == {}'.format(roll))
                    request = roll.split('d', 1)
                    rolls = 1
                    if request[0] != '':
                        rolls = int(request[0])
                    debug.debug(debug.D_INFO, 'rolls == {}'.format(rolls))
                    die = int(request[1])
                    debug.debug(debug.D_INFO, 'die == {}'.format(die))

                    max_rolls = 10

                    if rolls > max_rolls:
                        await send.message(
                            message.channel,
                            'Yeah... I\'m only rolling {} times.'.format(
                                max_rolls))
                        time.sleep(2)
                        if rolls > max_rolls + 10:
                            await send.message(message.channel, 'F**k you.')
                        time.sleep(3)
                        rolls = max_rolls
                    if die == 0:
                        await send.message(message.channel,
                                           strings.roll_zero(message))
                    else:
                        if rolls == 0:
                            await send.message(
                                message.channel,
                                'You want me to roll zero d{}\'s?'.format(die))
                            time.sleep(3)
                            await send.message(
                                message.channel,
                                '... well, I guess I\'m done then.')
                        elif rolls < 2:
                            await send.message(message.channel,
                                               'Rolling a d{}.'.format(die))
                        else:
                            await send.message(
                                message.channel,
                                'Rolling {} d{}\'s.'.format(rolls, die))
                        time.sleep(2)
                        for i in range(rolls):
                            n = random.randint(1, die)
                            await send.message(
                                message.channel,
                                '*Roll {}*: {}.'.format(i + 1, n))
                            time.sleep(2)

            # basic personal commands

            #  private message commands
            if str(message.channel.id) == private.anaeon_dm_id:

                if m.startswith('!talk'):
                    args = message.content.split(',')
                    msg = ''
                    for i in range(len(args)):
                        if i == 3:
                            #  add in the first chunk of message
                            msg = '{}{}'.format(msg, args[i])
                        elif i > 3:
                            #  add in the rest of the chunks including commas to replace those lost by re.split()
                            msg = '{},{}'.format(msg, args[i])
                    await send_talk(args[1].strip(), args[2].strip(),
                                    msg.strip())

            for mention in message.mentions:
                if mention == client.user and str(
                        message.author.id) == private.anaeon_id:
                    if '!debugon' in m:
                        if debug.DEBUG:
                            await send.message(message.channel,
                                               'Debug was already active.')

                        elif not debug.DEBUG:
                            debug.DEBUG = True
                            await send.message(
                                message.channel,
                                'Debug is now active at {} level.'.format(
                                    debug.D_HEADER[debug.D_CURRENT_LEVEL]))

                    if '!debugoff' in m:
                        if debug.DEBUG:
                            debug.DEBUG = False
                            await send.message(message.channel,
                                               'Debug is now off.')

                        elif not debug.DEBUG:
                            await send.message(message.channel,
                                               'Debug was already off.')

                    if '!debuglevel' in m:
                        if re.search('\\b0\\b|error', m):
                            debug.D_CURRENT_LEVEL = debug.D_ERROR
                            await send.message(
                                message.channel,
                                'Now logging debug at ERROR level.')

                        elif re.search('\\b1\\b|info', m):
                            debug.D_CURRENT_LEVEL = debug.D_INFO
                            await send.message(
                                message.channel,
                                'Now logging debug at INFO level and below.')

                        elif re.search('\\b2\\b|verbose', m):
                            debug.D_CURRENT_LEVEL = debug.D_VERBOSE
                            await send.message(
                                message.channel,
                                'Now logging debug at VERBOSE level and below.'
                            )

                    if '!embedtest' in m:
                        embed = discord.Embed(title='', color=ANA_COLOR)
                        embed.set_author(name='Test Author Name')
                        embed.add_field(name='Test Field 1',
                                        value='Test Value')
                        embed.add_field(name='Test Field 2', value='s;laksdfj')
                        embed.add_field(name='Multi-line',
                                        value='other\nstuff',
                                        inline=True)
                        embed.set_footer(text='Test Footer Text')
                        await send.message(message.channel, embed=embed)

                    if '!status' in m:
                        g = re.search('(?<=game=).+', m).group(0)
                        g_obj = discord.Game(name=g)
                        debug.debug(debug.D_VERBOSE,
                                    'game object = {}'.format(g_obj))
                        debug.debug(
                            debug.D_VERBOSE,
                            'Setting status to \"Playing {}\".'.format(g))
                        await client.change_presence(game=g_obj)
                        # await client.change_status(game=g_obj) # depricated
                        debug.debug(debug.D_VERBOSE, 'POST-AWAIT THING')

            # end basic personal commands

            # end general stuff

            # STUPID STUFF GOES HERE ============================

            if message.author.nick is not None:
                if 'duck' in message.author.nick.lower():
                    await send.message(message.channel, 'Quack.')
                if 'goose' in message.author.nick.lower():
                    await send.message(message.channel, 'Honk.')

            for regex in strings.no_words_regex:
                debug.debug(debug.D_VERBOSE,
                            'Checking for {} in "{}".'.format(regex, m))
                if re.search(regex, m):
                    debug.debug(
                        debug.D_INFO,
                        'A unacceptable word was used... attempting to delete it.'
                    )
                    # await client.delete_message(message)
                    r = strings.no_words_response
                    response = (r[random.randint(1, len(r)) - 1])
                    await send.message(message.channel, response)

                    time.sleep(2)

            if re.search(
                    '\\bfag(\\b|s)|\\bfaggot(\\b|s)|\\bfaggotry\\b|\\bgay(\\b|s)|\\bga{2,99}y(\\b|s)|\\blgbt\\b',
                    m):
                debug.debug(debug.D_INFO, 'Reacting to some faggotry.')
                try:
                    await send.reaction(message, '🏳️‍🌈')
                except discord.errors.HTTPException as e:
                    debug.debug(debug.D_ERROR, e)

            # GIV DEM BITCHES SOME LIZARDS
            if re.search('\\blizard(\\b|s)', m):
                await send_animal(message, 'lizard')

            # GIV DEM BITCHES SOME FOXES
            if re.search('\\bfox(\\b|s)',
                         m):  # Fold all of these into a big elif somehow.
                await send_animal(message, 'fox')

            for mention in message.mentions:

                if mention == client.user:
                    if 'anal' in m:
                        r = [
                            'I guess... if I open up the right ports.',
                            'That\'s not supposed to go there!',
                            '```Throughput error:\n\nIncorrect dataflow direction.```'
                        ]
                        response = (r[random.randint(1, len(r)) - 1])
                        await send.message(message.channel, response)

                    if 'suck' in m:
                        r = [
                            'Sorry, {}, I\'m not scripted for that kind of thing...'
                            .format(message.author.mention),
                            'I can get you a vacuum, if you\'d like.',
                            '```Packet error:\n\nSize smaller than expected.```'
                        ]
                        response = (r[random.randint(1, len(r)) - 1])
                        await send.message(message.channel, response)

                    if 'lick' in m:
                        r = [
                            'I don\'t exactly have a tongue, {}...'.format(
                                message.author.mention),
                            'People don\'t usually ask for stuff like that from anything python-related,'
                            'but everyone has their kinks, I guess.',
                            '```Error:\n\nPeripheral device driver not found.```'
                        ]
                        response = (r[random.randint(1, len(r)) - 1])
                        await send.message(message.channel, response)

                    if 'smash or pass' in m:
                        await send.message(message.channel,
                                           random.choice(['smash', 'pass']))

                    # END STUPID STUFF =================================

                    # SIMPLE RESPONSES =================================

                    if re.search('\\bthank(\\b|s)', m):
                        await send.message(message.channel,
                                           strings.youre_welcome(message))

                    if re.search(
                            '\\bhi\\b|\\bhey\\b|\\bhello\\b|\\bwhat\'s up\\b',
                            m):
                        await send.message(message.channel,
                                           strings.hi(message))

            # END SIMPLE RESPONSES =================================

            # Begin per-server message handling.

            # Only do these things in Digital Table server.

            if is_tdt:
                await tdt.handle_message(client, message)
Exemplo n.º 9
0
async def on_message(
        message):  # when someone sends a message. Read command inputs here.
    global CAN_DELETE
    global TALKATIVE
    global gui

    # gui.add_chat_message(message)

    m_guild = 'Unknown'
    m_guild_id = 'None'
    m_channel = 'Unknown'
    m_channel_id = 'None'

    if message.guild is not None:
        m_guild = str(message.guild)
        m_guild_id = str(message.guild.id)

    if message.channel is not None:
        m_channel = str(message.channel)
        m_channel_id = str(message.channel.id)

    debug.debug(
        debug.D_INFO,
        '[G:{}][C:{}][A:{}]:{}'.format(m_guild, m_channel, message.author,
                                       message.content))
    debug.debug(
        debug.D_VERBOSE, '[G:{}][C:{}][A:{}]'.format(m_guild_id, m_channel_id,
                                                     message.author.id))

    # go ahead and check which server we're in
    is_neon = False
    is_durg = False
    is_tdt = m_guild_id == str(private.tdt_server_id)
    debug.debug(debug.D_VERBOSE, 'TDT == ' + str(is_tdt))

    m = message.content.lower()
    if message.author != client.user:  # don't react to your own messages.

        # Do these things in general...

        # Only if mentioned
        for mention in message.mentions:
            if mention == client.user:
                if re.search('\\bshut up\\b', m):
                    debug.debug(debug.D_INFO, 'Silencing the bot.')
                    TALKATIVE = False
                    await send.message(message.channel, 'Understood.')

                if re.search('\\bspeak up\\b', m):
                    debug.debug(debug.D_INFO, 'Unsilencing the bot.')
                    TALKATIVE = True
                    await send.message(message.channel, 'Understood.')

                if re.search('\\bdelete stuff\\b', m):
                    # if hasattr(client, discord.Permissions.manage_messages):
                    debug.debug(debug.D_INFO,
                                'Deleting things from this point.')
                    CAN_DELETE = True
                    await send.message(message.channel, 'Understood.')
                    # else:
                    # await send.message(message.channel, 'I do not have permission to do that from the server\'s owner.')

                if re.search('\\bdo not delete stuff\\b', m):
                    debug.debug(debug.D_INFO, 'No longer deleting things.')
                    CAN_DELETE = False
                    await send.message(message.channel, 'Understood.')

        if re.search('\\broll\\b', m):
            sm = m.replace(' ', '')
            sresult = re.search('(?<=roll)*\d+d\d+', sm)
            if re.search('d\d+', sm):
                if sresult is None:
                    sresult = re.search('(?<=roll)*d\d+', sm)
                if sresult is None:
                    pass
                roll = sresult.group(0)
                debug.debug(debug.D_INFO, 'roll == {}'.format(roll))
                request = roll.split('d', 1)
                rolls = 1
                if request[0] != '':
                    rolls = int(request[0])
                debug.debug(debug.D_INFO, 'rolls == {}'.format(rolls))
                die = int(request[1])
                debug.debug(debug.D_INFO, 'die == {}'.format(die))

                max_rolls = 10

                if rolls > max_rolls:
                    await send.message(
                        message.channel,
                        'Yeah... I\'m only rolling {} times.'.format(
                            max_rolls))
                    time.sleep(2)
                    if rolls > max_rolls + 10:
                        await send.message(message.channel, 'F**k you.')
                    time.sleep(3)
                    rolls = max_rolls
                if die == 0:
                    await send.message(message.channel,
                                       strings.roll_zero(message))
                else:
                    if rolls == 0:
                        await send.message(
                            message.channel,
                            'You want me to roll zero d{}\'s?'.format(die))
                        time.sleep(3)
                        await send.message(
                            message.channel,
                            '... well, I guess I\'m done then.')
                    elif rolls < 2:
                        await send.message(message.channel,
                                           'Rolling a d{}.'.format(die))
                    else:
                        await send.message(
                            message.channel,
                            'Rolling {} d{}\'s.'.format(rolls, die))
                    time.sleep(2)
                    for i in range(rolls):
                        n = random.randint(1, die)
                        await send.message(message.channel,
                                           '*Roll {}*: {}.'.format(i + 1, n))
                        time.sleep(2)

        # basic personal commands

        #  private message commands
        if message.channel.id == private.anaeon_dm_id:

            # !talk
            if m.startswith('!talk'):
                args = message.content.split(',')
                msg = ''
                for i in range(len(args)):
                    if i == 3:
                        #  add in the first chunk of message
                        msg = '{}{}'.format(msg, args[i])
                    elif i > 3:
                        #  add in the rest of the chunks including commas to replace those lost by re.split()
                        msg = '{},{}'.format(msg, args[i])
                await send_talk(args[1].strip(), args[2].strip(), msg.strip())

        for mention in message.mentions:
            if message.author.id != private.anaeon_id:
                pass
            elif mention == client.user and message.author.id == private.anaeon_id:
                if '!debugon' in m:
                    if debug.DEBUG:
                        await send.message(message.channel,
                                           'Debug was already active.')

                    elif not debug.DEBUG:
                        debug.DEBUG = True
                        await send.message(
                            message.channel,
                            'Debug is now active at {} level.'.format(
                                debug.D_HEADER[debug.D_CURRENT_LEVEL]))

                if '!debugoff' in m:
                    if debug.DEBUG:
                        debug.DEBUG = False
                        await send.message(message.channel,
                                           'Debug is now off.')

                    elif not debug.DEBUG:
                        await send.message(message.channel,
                                           'Debug was already off.')

                if '!debuglevel' in m:
                    if re.search('\\b0\\b|error', m):
                        debug.D_CURRENT_LEVEL = debug.D_ERROR
                        await send.message(
                            message.channel,
                            'Now logging debug at ERROR level.')

                    elif re.search('\\b1\\b|info', m):
                        debug.D_CURRENT_LEVEL = debug.D_INFO
                        await send.message(
                            message.channel,
                            'Now logging debug at INFO level and below.')

                    elif re.search('\\b2\\b|verbose', m):
                        debug.D_CURRENT_LEVEL = debug.D_VERBOSE
                        await send.message(
                            message.channel,
                            'Now logging debug at VERBOSE level and below.')

                    elif re.search('\\b3\\b|vomit', m):
                        debug.D_CURRENT_LEVEL = debug.D_VOMIT
                        await send.message(message.channel,
                                           'Now logging EVERYTHING.')

                if '!embedtest' in m:
                    embed = discord.Embed(title='', color=misc.ANA_COLOR)
                    embed.set_author(name='Test Author Name')
                    embed.add_field(name='Test Field 1', value='Test Value')
                    embed.add_field(name='Test Field 2', value='s;laksdfj')
                    embed.add_field(name='Multi-line',
                                    value='other\nstuff',
                                    inline=True)
                    embed.set_footer(text='Test Footer Text')
                    await send.message(message.channel, embed=embed)

                if '!status' in m:
                    g = re.search('(?<=game=).+', m).group(0)
                    # g_obj = discord.Activity(name=g)
                    # debug.debug(debug.D_VERBOSE, 'game object = {}'.format(g_obj))
                    debug.debug(debug.D_VERBOSE,
                                'Setting status to \"Playing {}\".'.format(g))
                    await client.change_presence(
                        status=discord.Status.online,
                        activity=discord.CustomActivity(name=g))
                    # await client.change_status(game=g_obj) # depricated
                    debug.debug(debug.D_VERBOSE, 'POST-AWAIT THING')

                if '!cleanimagecache' in m:
                    await send.message(message.channel,
                                       'Cleaning up my image cache...')
                    await hash_images()
                    await send.message(message.channel, 'Done.')

                if '!reboot' in m or '!restart' in m:
                    await client.get_user(108467075613216768).send(
                        'Shutting down.')
                    await client.close()

                if '!exe' in message.content:
                    log.info('Running custom code.')
                    code = message.content.replace(
                        '<@!297237845591195651> !exe ', '')
                    locs = locals()
                    new_code = f'async def _ex(locs): '
                    log.debug(code)
                    if 'await' in code or 'async' in code:
                        try:
                            log.info('Running code as async.')
                            for line in code.split('\n'):
                                new_code = new_code + f'\n    ' + line
                            exec(new_code)
                            await locals()['_ex'](locs)
                            # THIS SHIT BE DANGEROUS AS F**K, YO. PROTECT THAT SHIT.
                            log.debug('Code ran successfully.')
                        except BaseException as e:
                            log.exception('Code failed.')
                            await send.message(message.channel, str(e))
                            await send.message(
                                message.channel,
                                '```python\n' + new_code + '```')
                    else:
                        try:
                            exec(code, globals(), locals())
                            # THIS SHIT BE DANGEROUS AS F**K, YO. PROTECT THAT SHIT.
                            log.debug('Code ran successfully.')
                        except BaseException as e:
                            log.exception('Code failed.')
                            await send.message(message.channel, str(e))
                            await send.message(message.channel,
                                               '```python\n' + code + '```')

        # end basic personal commands

        # end general stuff

        # STUPID STUFF GOES HERE ============================

        if hasattr(message.author,
                   'nick') and message.author.nick is not None and TALKATIVE:
            if 'duck' in message.author.nick.lower():
                await send.message(message.channel, 'Quack.')
            if 'goose' in message.author.nick.lower():
                await send.message(message.channel, 'Honk.')
            if 'fox' in message.author.nick.lower():
                await send.message(message.channel, 'Yiff.')

        for regex in strings.no_words_regex:
            debug.debug(debug.D_VOMIT,
                        'Checking for {} in "{}".'.format(regex, m))
            if re.search(regex, m):
                debug.debug(
                    debug.D_INFO,
                    'A unacceptable word was used... attempting to delete it.')
                if CAN_DELETE:
                    try:
                        await message.delete()
                    except PermissionError as e:
                        debug.debug(debug.D_ERROR, e)
                    except discord.errors.Forbidden as e:
                        debug.debug(debug.D_ERROR, e)
                    except discord.errors.NotFound as e:
                        debug.debug(debug.D_ERROR, e)
                await send.message(message.channel,
                                   strings.no_words_response(message))

                time.sleep(2)

        # GIV DEM BITCHES SOME LIZARDS
        if re.search('\\blizard(\\b|s)', m):
            await send_animal(message, 'lizard')

        # GIV DEM BITCHES SOME FOXES
        if re.search('\\bfox(\\b|s)',
                     m):  # Fold all of these into a big elif somehow.
            await send_animal(
                message, 'fox'
            )  # No, because an elif would mean it can't catch multiple in the same msg.
        # HONK
        if re.search('\\bhonk\\b', m):
            await send_animal(message, 'goose')

        for mention in message.mentions:

            if mention == client.user and TALKATIVE:
                if 'anal' in m:
                    r = [
                        'I guess... if I open up the right ports.',
                        'That\'s not supposed to go there!',
                        '```Throughput error:\n\nIncorrect dataflow direction.```'
                    ]
                    response = (r[random.randint(1, len(r)) - 1])
                    await send.message(message.channel, response)

                if 'suck' in m:
                    r = [
                        'Sorry, {}, I\'m not scripted for that kind of thing...'
                        .format(message.author.mention),
                        'I can get you a vacuum, if you\'d like.',
                        '```Packet error:\n\nSize smaller than expected.```'
                    ]
                    response = (r[random.randint(1, len(r)) - 1])
                    await send.message(message.channel, response)

                if 'lick' in m:
                    r = [
                        'I don\'t exactly have a tongue, {}...'.format(
                            message.author.mention),
                        'People don\'t usually ask for stuff like that from anything python-related,'
                        'but everyone has their kinks, I guess.',
                        '```Error:\n\nPeripheral device driver not found.```'
                    ]
                    response = (r[random.randint(1, len(r)) - 1])
                    await send.message(message.channel, response)

                if 'smash or pass' in m:
                    await send.message(message.channel,
                                       random.choice(['smash', 'pass']))

                # END STUPID STUFF =================================

                # SIMPLE RESPONSES =================================

                if re.search('\\bthank(\\b|s)', m):
                    await send.message(message.channel,
                                       strings.youre_welcome(message))

                if re.search('\\bhi\\b|\\bhey\\b|\\bhello\\b|\\bwhat\'s up\\b',
                             m):
                    await send.message(message.channel, strings.hi(message))

        # END SIMPLE RESPONSES =================================

        # Begin per-server message handling.

        # Only do these things in Digital Table server.

        if is_tdt:
            await tdt.handle_message(client, message, TALKATIVE)
Exemplo n.º 10
0
async def daily_old():
    try:
        _now = datetime.now()
        _next = storage.load_bot_setting('next_wotd_datetime')
        debug.debug(
            debug.D_VOMIT, 'Current time: {} Next reset: {}'.format(
                _now.strftime('%H:%M:%S'), _next.strftime('%H:%M:%S')))
        if _now > _next:
            # DO DAILY STUFF HERE

            await tdt.daily()

            # NO DAILY STUFF PAST THIS LINE
    except KeyError as e:
        debug.debug(debug.D_ERROR, e)
        x = datetime.today()  # today
        if datetime.now().hour < 17:
            y = x.replace(hour=17, minute=0, second=0,
                          microsecond=0)  # today at 5pm
        else:
            if x.day + 1 <= calendar.monthrange(x.year, x.month)[1]:
                y = x.replace(day=x.day + 1,
                              hour=17,
                              minute=0,
                              second=5,
                              microsecond=0)  # tomorrow at 5pm
            else:
                if x.month + 1 <= 12:
                    #  first day of next month at 5pm
                    y = x.replace(month=x.month + 1,
                                  day=1,
                                  hour=17,
                                  minute=0,
                                  second=5,
                                  microsecond=0)
                else:
                    y = x.replace(year=x.year + 1,
                                  month=1,
                                  day=1,
                                  hour=17,
                                  minute=0,
                                  second=5,
                                  microsecond=0)
        storage.save_bot_setting('next_wotd_datetime', y)
    except AttributeError as e:
        debug.debug(debug.D_ERROR, e)
    debug.debug(
        debug.D_VOMIT, 'Time to next wotd: {}'.format(
            (storage.load_bot_setting('next_wotd_datetime') - datetime.now())))

    # ensure that the timer is reset
    x = datetime.today()  # today
    if datetime.now().hour < 17:
        y = x.replace(hour=17, minute=0, second=0,
                      microsecond=0)  # today at 5pm
    else:
        if x.day + 1 <= calendar.monthrange(x.year, x.month)[1]:
            y = x.replace(day=x.day + 1,
                          hour=17,
                          minute=0,
                          second=0,
                          microsecond=0)  # tomorrow at 5pm
        else:
            if x.month + 1 <= 12:
                #  first day of next month at 5pm
                y = x.replace(month=x.month + 1,
                              day=1,
                              hour=17,
                              minute=0,
                              second=0,
                              microsecond=0)
            else:
                y = x.replace(year=x.year + 1,
                              month=1,
                              day=1,
                              hour=17,
                              minute=0,
                              second=0,
                              microsecond=0)

    delta_t = y - x  # time between now and next reset
    secs = delta_t.seconds + 1

    # t = Timer(secs, resetPointsToGive(server))

    storage.save_bot_setting('next_wotd_datetime', y)
Exemplo n.º 11
0
def reset_points_to_give(server):
    users = server.members
    response = 'The following users have been given new points to use:'
    new_points_given = False
    for user in users:
        user_points_left = 0
        debug.debug(debug.D_INFO, 'Checking ' + str(user.name) + '...')
        try:
            user_points_left = storage.get_user_attribute(
                server.id, user.id, 'available_pearl_points')
            debug.debug(debug.D_INFO, str(user_points_left) + ' points left.')
            if user_points_left < pointToGiveCap:
                give = user_points_left + dailyPoints
                debug.debug(debug.D_INFO,
                            'Giving ' + str(dailyPoints) + ' point(s).')
                storage.set_user_attribute(server.id, user.id,
                                           'available_pearl_points', give)
                response = '{}||{}'.format(response, user.mention)
                new_points_given = True
        except KeyError as e:
            debug.debug(debug.D_INFO, 'Skipping Ana...')

    # await client.send_message(server, response)
    debug.debug(debug.D_INFO, 'Points to spend have been reset')
    x = datetime.today()  # today
    if datetime.now().hour < 17:
        y = x.replace(hour=17, minute=0, second=0,
                      microsecond=0)  # today at 5pm
    else:
        if x.day + 1 <= calendar.monthrange(x.year, x.month)[1]:
            y = x.replace(day=x.day + 1,
                          hour=17,
                          minute=0,
                          second=0,
                          microsecond=0)  # tomorrow at 5pm
        else:
            if x.month + 1 <= 12:
                #  first day of next month at 5pm
                y = x.replace(month=x.month + 1,
                              day=1,
                              hour=17,
                              minute=0,
                              second=0,
                              microsecond=0)
            else:
                y = x.replace(year=x.year + 1,
                              month=1,
                              day=1,
                              hour=17,
                              minute=0,
                              second=0,
                              microsecond=0)

    delta_t = y - x  # time between now and next reset
    secs = delta_t.seconds + 1

    # t = Timer(secs, resetPointsToGive(server))

    storage.set_server_attribute(server.id, 'next_pearl_point_reset_datetime',
                                 y)
    if not new_points_given:
        response = strings.no_players()
    return response
Exemplo n.º 12
0
def give_points(client, message):
    id = 'null'
    pearlpoints = 0
    response = '... nothing happened ...'
    if len(message.mentions) >= 3:
        return 'You can\'t send points to more than one person at a time.'
    for mention in message.mentions:
        debug.debug(debug.D_VERBOSE, 'Checking mention: ' + mention.name)
        debug.debug(debug.D_VERBOSE,
                    'mention != client.user : '******'mention != message.author : ' + str(mention != message.author))
        debug.debug(debug.D_VERBOSE, 'mention.bot : ' + str(mention.bot))
        if mention != client.user and mention != message.author and not mention.bot:
            ptg = 0
            try:
                ptg = storage.get_user_attribute(message.guild.id,
                                                 message.author.id,
                                                 'available_pearl_points')
            except KeyError as e:
                debug.debug(debug.D_ERROR, e)
            if ptg > 0:
                id = mention.id
                try:
                    pearlpoints = int(
                        storage.get_user_attribute(message.guild.id, id,
                                                   "pearl_points"))
                except KeyError as e:
                    debug.debug(
                        debug.D_ERROR,
                        '{} did not have a \'pearl_points\' attribute.'.format(
                            mention.name))
                    debug.debug(debug.D_ERROR, e)
                finally:
                    debug.debug(debug.D_INFO,
                                'Giving {} a point.'.format(mention))
                    pearlpoints += 1
                    storage.set_user_attribute(message.guild.id, id,
                                               "pearl_points", pearlpoints)
                    p = storage.get_user_attribute(message.guild.id, id,
                                                   "pearl_points")
                    debug.debug(debug.D_INFO,
                                '{} has {} points now.'.format(mention, p))
                    response = strings.give_point(mention)
                    response = "{}||Alright, I gave a point to {}.".format(
                        response, mention.mention)
                    if ptg - 1 == 1:
                        response = '{}||{}, you have {} point left to give.'.format(
                            response, message.author.mention, ptg - 1)
                    else:
                        response = '{}||{}, you have {} points left to give.'.format(
                            response, message.author.mention, ptg - 1)
                    storage.set_user_attribute(message.guild.id,
                                               message.author.id,
                                               'available_pearl_points',
                                               ptg - 1)
                    return response
            else:
                return 'You don\'t have any more points to give today, {}.'.format(
                    message.author.mention)
        else:
            response = 'I can\'t give a point to no one or myself.||'\
                'Try mentioning the person you want to give points to.'
    return response