Example #1
0
async def is_tag(ctx, user: str, *tag_question: str):
    """<name> <tag>: Is this person something?."""
    serv = to_filename(str(ctx.message.guild))
    #user = '******'.join(user)
    print('user parsed as: %s' % user)

    if len(ctx.message.mentions) > 0:
        print('mention detected')
        mention = ctx.message.mentions[0]
        name = get_name(ctx.message.mentions[0])
        print('name parsed as: %s' % name)
    else:
        name = user
        print('name parsed as: %s' % name)

    tag_question = ' '.join(tag_question)

    tags = tm.TagBank(serv)
    tagstring = tags.gettags(name)
    taglist = tagstring.split(', ')
    if tag_question in taglist:
        msg = 'yes'
    else:
        msg = 'no'
    await ctx.send(msg)
Example #2
0
async def tag(ctx, user: str, *tag: str):
    """<name> <tag>: Tag someone as something."""

    print('user: %s' % user)
    print('tag: %s' % str(tag))

    # detect multi word usernames:
    if '|' in tag:
        user2, tag = (' '.join(tag)).split(' | ')
        print("user2: %s\ntag: %s" % (user2, tag))
        user = user + ' ' + user2
    else:
        tag = ' '.join(tag)  # extract string from 1-tuple

    serv = to_filename(str(ctx.message.server))

    print('server name: %s' % serv)
    tags = tm.TagBank(serv)

    ret = tags.addtag(user, tag)
    tags.to_xml()

    if ret is not None:  # tagbank tells us there are no tags
        await bot.say(ret)
    else:
        await bot.say('Tag added.')
Example #3
0
async def tagged(ctx, *tag: str):
    """<tag>: Show everyone who is tagged as this."""
    serv = to_filename(str(ctx.message.server))
    print(tag)
    tag = ' '.join(tag)
    tags = tm.TagBank(serv)
    userstring = tags.gettagged(tag)
    await bot.say("%s: %s" % (tag, userstring))
Example #4
0
async def tags(ctx, *user: str):
    """<name>: Show someone's tags."""
    serv = to_filename(str(ctx.message.server))
    user = '******'.join(user)

    tags = tm.TagBank(serv)
    tagstring = tags.gettags(user)
    await bot.say("%s: %s" % (user, tagstring))
Example #5
0
async def tag(ctx, user: str, *tag: str):
    """<name> <tag>: Tag someone as something."""

    print('user: %s' % user)
    print('tag: %s' % str(tag))

    # detect multi word usernames:
    if '|' in tag:
        user2, tag = (' '.join(tag)).split(' | ')
        print("user2: %s\ntag: %s" % (user2, tag))
        user = user + ' ' + user2
    elif len(ctx.message.mentions) > 0:
        print('mention detected')
        mention = ctx.message.mentions[0]
        user = get_name(ctx.message.mentions[0])
        tag = ' '.join(tag)  # extract string from 1-tuple
    else:
        tag = ' '.join(tag)  # extract string from 1-tuple
    serv = to_filename(str(ctx.message.guild))

    print('server name: %s' % serv)
    tags = tm.TagBank(serv)

    # check for self taggers:
    if user.lower() == get_name(ctx.message.author, serv=None).lower():
        msg = random.choice(bot.shames)
        tags = tm.TagBank(serv)
        ret = tags.addtag(user, 'self tagger')
        tags.to_xml()

        await ctx.send(msg)

    else:
        ret = tags.addtag(user, tag)
        tags.to_xml()

        if ret is not None:  # tagbank tells us there are no tags
            await ctx.send(ret)
        else:
            tagstring = tags.gettags(user)
            await ctx.send("%s: %s" % (user, tagstring))
Example #6
0
async def tags(ctx, *user: str):
    """<name>: Show someone's tags."""
    serv = to_filename(str(ctx.message.guild))
    user = '******'.join(user)
    print('user parsed as: %s' % user)

    if len(ctx.message.mentions) > 0:
        print('mention detected')
        mention = ctx.message.mentions[0]
        name = get_name(ctx.message.mentions[0])
        print('name parsed as: %s' % name)
    else:
        name = user
        print('name parsed as: %s' % name)

    tags = tm.TagBank(serv)
    tagstring = tags.gettags(name)
    await ctx.send("%s: %s" % (name, tagstring))
Example #7
0
def get_name(author, serv=None):
    """Gets the name or nick of an Author object
    or randomly uses one of their tags if serv isn't None
    assumes serv is a cleaned up string that can be passed to tagbank"""
    name = author.nick
    if name is None:
        name = str(author).split('#')[0]

    if serv is not None:  # if serv is None, we just get their actual name, else we pick a fun tag from that server's tagbank:
        tags = tm.TagBank(serv)  # get tags
        tagstring = tags.gettags(name.lower())
        if tagstring == 'No tags.':
            return name
        else:
            taglist = tagstring.split(', ')
            possible_names = taglist + [name]  # list of real name and tags
            newname = random.choice(possible_names)  # choose one randomly
            return newname
    else:
        return name
Example #8
0
import tag_manager as tm
import corpus_manager as cm

from quote_utils import qparse, to_filename, is_number

token = 'NDA0MjIyMTM0OTQ5MzgwMTA2.DUSzYg.OUrC1agKwJOsRJV9uLsRgSeN67U'
description = None

bot = commands.Bot(command_prefix='.', description=description)
bot.remove_command('help')

# features to be added:
# name and shame self quote abusers
# and self taggers

tags = tm.TagBank('discord')
last_reply = 0


@bot.event
async def on_ready():
    print('Logged in as')
    print(bot.user.name)
    print(bot.user.id)
    print('------')

    bot.last_reply = 0

    print([str(x) for x in bot.servers])

Example #9
0
async def q(ctx, arg1: str = 'all', *words: str):
    """add <name> <quote>: Adds a quote to someone.
    <name> [<idx>]: Retrieves a quote from someone, optionally indexed by quote number."""
    serv = to_filename(str(ctx.message.guild))

    print('server name: %s' % serv)
    quotes = qm.QuoteBank(serv)

    if arg1 == 'add':
        # add a quote
        user = words[0]

        if '|' in words:  # detect multi-word usernames
            user, restwords = (' '.join(words)).split(' | ')

            fullmsg = ctx.message.content  # have to parse the full message to preserve newlines
            msg = fullmsg.split('| ')[1]  # separate out the |
        elif len(ctx.message.mentions) > 0:
            print('mention detected')
            mention = ctx.message.mentions[0]
            user = get_name(ctx.message.mentions[0])
            fullmsg = ctx.message.content
            print('fullmsg: %s' % fullmsg)
            id = "<@%s>" % ctx.message.mentions[0].id
            msg = fullmsg.split('.q add ' + id + ' ')[1]
            print('msg: %s' % msg)

        else:
            fullmsg = ctx.message.content  # have to parse the full message to preserve newlines
            msg = fullmsg.split('.q add ' + user +
                                ' ')[1]  # separate out the .q add

        quote = qparse(msg, user)

        print('Adding quote:\n%s::%s' % (user, quote))

        # check for self quoting:
        if user.lower() == get_name(ctx.message.author, serv=None).lower():
            msg = random.choice(bot.shames)
            tags = tm.TagBank(serv)
            ret = tags.addtag(user, 'self quoter')
            tags.to_xml()

            # await bot.say(msg)
            await ctx.send(msg)

        else:
            quotes.add(user, quote)
            #quotes.to_xml()
            await ctx.send('Quote added.')

    else:
        # say a quote
        if arg1 == 'all':  # grab a quote irrespective of user
            q = quotes.allquote()
        elif is_number(arg1):
            # get an allquote with index
            q = quotes.allquote(int(arg1))

        else:  # grab a random quote from the named user
            user = arg1
            if '|' in words:  # detect multi line usernames
                user, words = (' '.join(words)).split(' | ')
            elif len(ctx.message.mentions) > 0:  # detect mentions
                print('mention detected')
                mention = ctx.message.mentions[0]
                user = get_name(ctx.message.mentions[0]
                                )  # keep words the same; the mention is arg1

            if len(
                    words
            ) > 0:  # we've been asked for an index, or a multi line username, or both
                if is_number(words[-1]):  # there is an index
                    idx = int(words[-1])  # retrieve index

                    words = words[:-1]
                    if len(words
                           ) > 0:  # are we dealing with a multi word username?
                        user = "******" % (user, ' '.join(words)
                                          )  # complete the username
                    q = quotes.get(user, idx)  # multi word username with index
                else:  # no index, just a multi word username on its own
                    user = "******" % (user, ' '.join(words))
                    q = quotes.get(user)  # multi word username without index

            else:  # get a random quote
                q = quotes.get(user)

        await ctx.send(q)