Ejemplo n.º 1
0
def call(msg):
    """Returns a random integer.
    
    If no args given, returns a number between 1 and 100.
    If one arg given, returns a number between 1 and <arg>.
    If two args given, returns a number between <arg1> and <arg2>."""
    content = msg.get("d").get("content")
    parts = content.split()
    if len(parts) == 1:
        minval = 1
        maxval = 100
    elif len(parts) == 2:
        minval = 1
        maxval = int(parts[1])
    else:
        minval = int(parts[1])
        maxval = int(parts[2])

    if minval > maxval:
        minval, maxval = maxval, minval
    randno = random.randint(minval, maxval)

    if minval == maxval:
        bot_utils.reply(msg, "Your number is %s. What a surprise." % randno)
    else:
        bot_utils.reply(msg, "Your number is %s." % randno)
Ejemplo n.º 2
0
def blink(msg):
    """Send arbitrary message to the destination, then delete the message"""
    content = msg.get("d").get("content")
    try:
        _, dest, response = content.split(None, 2)
    except ValueError:
        reply = "Invalid format, expected destination and message."
        bot_utils.reply(msg, reply)
        return

    # User DM IDs are different from their user IDs
    if dest.startswith('<@'):
        dest = bot_utils.get_dm(dest)

    # Dest could be a naked ID or a bracket-wrapped format
    matches = re.match(r'\<.(\d+)\>', dest)
    if matches:
        dest = matches.group(1)

    # Hijack the bot_utils.reply function
    fake = dict(msg)
    fake["d"]["channel_id"] = dest
    response = bot_utils.reply(fake, response)
    msg_id = response.json()['id']
    chan_id = response.json()['channel_id']
    bot_utils.HTTP_SESSION.request(
        'DELETE', '/channels/{0}/messages/{1}'.format(chan_id, msg_id))
Ejemplo n.º 3
0
def doit(msg):
    """What do you think this does?"""
    content = msg.get("d").get("content")
    if ' ' in content:
        target = content.split(' ', 1)[1]
    else:
        target = "<@%s>" % msg["d"]["author"]["id"]
    bot_utils.reply(
        msg,
        "*sneaks up behind %s and gives them surprisebuttsecks.*" % target)
Ejemplo n.º 4
0
def call(msg):
    """Discordianism is cool."""
    day, weekday, season, year, istib = ddate()
    if istib:
        result = "Today is St. Tib's day in the YOLD %s" % year
    else:
        result = (
            "Today is %s, the %s%s day of %s in the YOLD %s" %
            (WEEKDAYS[weekday], day, ordinalise(day), SEASONS[season], year))
    bot_utils.reply(msg, result)
Ejemplo n.º 5
0
def command(msg):
    """Reply with {cc}pong, and any args passed to the original {cc}ping."""
    content = msg.get("d").get("content")
    if ' ' in content:
        reply = u"{0}pong {1}".format(config.COMMAND_CHAR,
                                      content.split(' ', 1)[1])
    else:
        reply = u"{0}pong".format(config.COMMAND_CHAR)

    bot_utils.reply(msg, reply)
Ejemplo n.º 6
0
def quitguild(msg):
    """Leave a guild (server)"""
    content = msg.get("d").get("content")
    if ' ' in content:
        guildid = content.split(' ', 1)[1]
    else:
        bot_utils.reply(msg, "channel ID missing")

    bot_utils.HTTP_SESSION.delete(
        "/users/@me/guilds/{guildid}".format(guildid=guildid))
    bot_utils.reply(msg, "Done")
Ejemplo n.º 7
0
def handle(msg):
    if msg.get("t") == "MESSAGE_CREATE":
        content = msg.get("d").get("content")
        # Respond to !ping with !pong
        if content == "!foo":
            reply = u"!bar"
        # If the !ping has content attached, match this content in the output
        elif content.startswith("!foo "):
            reply = u"!bar " + msg.get("d").get("content").split(' ', 1)[1]
        else:
            return
        bot_utils.reply(msg, reply)
Ejemplo n.º 8
0
def command_add(msg):
    """Add a new alias for yourself"""
    if msg["d"].get("content").count(" ") < 1:
        bot_utils.reply(msg, "Invalid format")
        return

    _, nick = msg["d"].get("content").split(" ", 1)
    uid = msg["d"].get("author", {}).get("id")

    ALIASES[uid] = nick
    write_aliases(config.USERSEARCH_ALIASES_FNAME)
    bot_utils.reply(msg, "<@!{0}> is now {1} on the site".format(uid, nick))
Ejemplo n.º 9
0
def command(msg):
    """Return the Discord ID of the mentioned user, or the ID of the user who sent the message."""
    content = msg.get("d").get("content")
    if ' ' in content:
        arg = content.split()[1]
        matches = re.match(r'\<\@(\d+)\>', arg)
        if matches:
            reply = "Discord UserID %s" % matches.group(1)
        else:
            reply = "Invalid format"
    else:
        userid = msg["d"]["author"]["id"]
        reply = "Discord UserID %s" % userid
    bot_utils.reply(msg, reply)
Ejemplo n.º 10
0
def uno_start(msg):
    """Creates a game of uno. Other commands are:
    {cc}cards, {cc}draw, {cc}join, {cc}leave, {cc}pass, {cc}play, {cc}players, {cc}start, {cc}stop, {cc}top, {cc}turn"""
    game = get_game(msg)
    if game:
        bot_utils.reply(
            msg, "There is already a game in progress (owned by {0})".format(
                game.owner))
        return

    game = Uno_Controller(msg)
    GAMES[game.key] = game
    response = "{0} started a game of uno! Type {1}join to join."
    bot_utils.reply(msg, response.format(game.owner, config.COMMAND_CHAR))
Ejemplo n.º 11
0
def command(msg):
    """Return the Discord ID of the mentioned channel, or the ID of the channel where the message was sent."""
    content = msg.get("d").get("content")
    if ' ' in content:
        arg = content.split()[1]
        matches = re.match(r'\<\#(\d+)\>', arg)
        if matches:
            reply = "Discord channel ID %s" % matches.group(1)
        else:
            reply = "Invalid format"
    else:
        userid = msg["d"]["channel_id"]
        reply = "Discord channel ID %s" % userid
    bot_utils.reply(msg, reply)
Ejemplo n.º 12
0
def doit(msg):
    """Measure lewdness of target"""
    content = msg.get("d").get("content")
    if ' ' in content:
        target = content.split(' ', 1)[1].strip()
    else:
        target = "<@%s>" % msg["d"]["author"]["id"]

    try:
        lewdness = MEASUREMENTS[target]
    except KeyError:
        lewdness = MEASUREMENTS.setdefault(target, get_lewdness(target))

    bot_utils.reply(msg, u"{0} is {1:0.1f}% lewd".format(target, lewdness))
Ejemplo n.º 13
0
def call(msg):
    """Ask the heathen a Would You Rather question"""

    # "Vendetta is awesome he's so totally sexy too"
    # - Vendetta

    global Q_INDEX

    if Q_INDEX < 0:
        random.shuffle(QUESTIONS)
        Q_INDEX = len(QUESTIONS)

    Q_INDEX -= 1
    reply = "<@%s>: %s" % (msg["d"]["author"]["id"], QUESTIONS[Q_INDEX])
    bot_utils.reply(msg, reply)
Ejemplo n.º 14
0
def call(msg):
    """For help with a particular command, type _{cc}help command_."""
    content = msg.get("d").get("content")
    if ' ' in content:
        command = content.split(None)[1].lower().strip(config.COMMAND_CHAR)
        if command in bot_utils.COMMANDS:
            reply = bot_utils.COMMANDS[command].__doc__ or "No help available"
        else:
            reply = "Unknown command"
    else:
        reply = "Available commands: {cc}%s.\nFor help with a particular command, type _{cc}help command_"
        helplist = list(bot_utils.COMMANDS.keys())
        helplist.sort()
        reply %= ', {cc}'.join(helplist)

    if reply[-1] not in ('.', '?', '!'):
        reply += '.'
    if '{cc}' in reply:
        reply = reply.format(cc=config.COMMAND_CHAR)
    bot_utils.reply(msg, reply)
Ejemplo n.º 15
0
def do_command(msg):
    """Check if we need to call a keyword-style command."""
    # If this isn't a spoken chat message, ignore it
    if msg.get("t") != "MESSAGE_CREATE":
        return

    # If the message doesn't begin with our command char, ignore it
    content = msg.get("d").get("content")
    if not content.startswith(config.COMMAND_CHAR):
        return

    # If the command came from a bot, do not respond
    if msg["d"]["author"].get("bot") and not config.BOT_COMMANDS:
        return

    # Remove the command prefix from the message
    content = content[len(config.COMMAND_CHAR):]

    # Do we have args for this command?
    if ' ' in content:
        content = content.split(' ', 1)[0]

    # Normalise case
    content = content.lower()

    # Check whether a dynamic content handler will take this
    handled = False
    for regex in bot_utils.RECOMMANDS:
        if (re.match(regex, content)):
            handled = True

    # Ignore a lone command character
    if not content:
        pass
    # Is the command recognised? If so, call it
    elif content in bot_utils.COMMANDS:
        bot_utils.COMMANDS[content](msg)
    elif not handled:
        bot_utils.reply(
            msg, "Unknown command: _{0}{1}_.".format(config.COMMAND_CHAR,
                                                     content))
Ejemplo n.º 16
0
def call(msg):
    """Summon a random loli for you."""
    content = msg.get("d").get("content")
    if ' ' in content:
        thing = content.split(None, 1)[1]
    else:
        thing = "loli"

    age = "%s year old" % random.randint(5, 15)
    text = "_%s %s %s, with %s %s eyes, %s %s hair, and is %s She %s_" % (
        random.choice(SUMMON),
        age,
        thing,
        random.choice(EYETYPE),
        random.choice(EYECOLOUR),
        random.choice(HAIRSTYLE),
        random.choice(HAIRCOLOUR),
        random.choice(CLOTHES),
        random.choice(AFTERMATH),
    )
    bot_utils.reply(msg, text)
Ejemplo n.º 17
0
    def _privmsg(self, msg, player=None):
        """Send a PRIVMSG to the specified Player.
        
        If no user is specified, send it to the channel intead.
        """
        # Get our destination ID
        # Make sure player is a class instance, not just the indentifier
        player = self.game.get_player(player)

        if player:
            destination = bot_utils.get_dm(player.identifier)
        else:
            destination = self.channel

        # Sanitise in case we have <> wrapper around the ID
        matches = re.match(r'\<.(\d+)\>', destination)
        if matches:
            destination = matches.group(1)

        # Hijack the bot_utils.reply function
        fake = {"d": {"channel_id": destination}}
        bot_utils.reply(fake, msg)
Ejemplo n.º 18
0
def command(msg):
    """Send arbitrary commands to the specified destination. Works for channels and @Users."""
    content = msg.get("d").get("content")
    try:
        _, dest, response = content.split(None, 2)
    except ValueError:
        reply = "Invalid format, expected destination and message."
        bot_utils.reply(msg, reply)
        return

    # User DM IDs are different from their user IDs
    if dest.startswith('<@'):
        dest = bot_utils.get_dm(dest)

    # Dest could be a naked ID or a bracket-wrapped format
    matches = re.match(r'\<.(\d+)\>', dest)
    if matches:
        dest = matches.group(1)

    # Hijack the bot_utils.reply function
    fake = dict(msg)
    fake["d"]["channel_id"] = dest
    bot_utils.reply(fake, response)
Ejemplo n.º 19
0
def command_del(msg):
    """Remove an alias."""
    if msg["d"].get("content").count(" ") != 1:
        bot_utils.reply(msg, "Invalid format")
        return

    uid = msg["d"].get("content").split(" ")[1]
    if not re.match(r'\<\@(\d+)\>', uid):
        bot_utils.reply(msg, "Invalid format")
        return
    uid = uid[2:-1]

    if uid in ALIASES:
        del ALIASES[uid]
        write_aliases(config.USERSEARCH_ALIASES_FNAME)
        bot_utils.reply(msg, "Alias deleted")
    else:
        bot_utils.reply(msg, "User has no alias")
Ejemplo n.º 20
0
def command_add(msg):
    """Add a new alias for another user."""
    if msg["d"].get("content").count(" ") < 2:
        bot_utils.reply(msg, "Invalid format")
        return

    _, uid, nick = msg["d"].get("content").split(" ", 2)
    uid = uid.strip('<!@>')
    if not re.match(r'(\d+)', uid):
        bot_utils.reply(msg, "Invalid format")
        return

    ALIASES[uid] = nick
    write_aliases(config.USERSEARCH_ALIASES_FNAME)
    bot_utils.reply(msg, "<@!{0}> is now {1} on the site".format(uid, nick))
Ejemplo n.º 21
0
def command_search(msg):
    """Return the lolicit profile for the given user."""
    # If we have an argument provided, use that
    if ' ' in msg["d"].get("content"):
        nick = msg["d"].get("content").split(None, 1)[1]

        if nick.startswith('<@'):
            # If there's a UID provided, try to alias it (or fail)
            nick = ALIASES.get(nick.strip('<!@>'))
            if not nick:
                bot_utils.reply(msg,
                                "Sorry, can you do that again without the @?")
                return
        else:
            # Take the argument as a literal username
            pass

    # No arg provided, query the user who posted the message
    else:
        # Do we have a UID alias for this?
        uid = "<@{0}>".format(msg["d"].get("author", {}).get("id"))
        nick = ALIASES.get(uid.strip('<!@>'))
        # If no UID, get the username (or aliased nick)
        if not nick:
            nick = msg["d"].get("member", {}).get("nick")
        if not nick:
            nick = msg["d"].get("author", {}).get("username")

    # Do search
    try:
        results = search_nick(nick)
        bot_utils.reply(msg, prettyprint(results))
    except ValueError:
        bot_utils.reply(msg, "Unknown username")
    except:
        bot_utils.reply(msg, "Error sending")
Ejemplo n.º 22
0
def all_dice_cmd(msg):
    """
    The real handler for arbitrary dice rolls
    """
    if msg.get("t") != "MESSAGE_CREATE":
        return
    content = msg.get("d").get("content")

    if not content.startswith(config.COMMAND_CHAR):
        return

    content = content.lstrip(config.COMMAND_CHAR)
    match = re.match(r"(\d*)d(\d+)", content, re.I)

    if not match:
        return

    try:
        sides = int(match.group(2))
        if match.group(1):
            count = int(match.group(1))
        else:
            count = 1
        if count > 100:
            bot_utils.reply(msg, "I don't have that many dice...")
            return
        elif count < 1:
            bot_utils.reply(msg, "You rolled nothing!")
            return
    except:
        # Badly-formed command, ignore it
        return

    rolls = [str(random.randint(1, sides)) for _ in range(count)]
    rollstr = "You rolled %s" % (", ".join(rolls))
    bot_utils.reply(msg, rollstr)
Ejemplo n.º 23
0
def doboobs(msg):
    """Everyone likes boobs."""
    reply = u"\u0460"
    bot_utils.reply(msg, reply)
Ejemplo n.º 24
0
 def decorated_f(msg):
     game = get_game(msg)
     if not game:
         bot_utils.reply(msg, "Error, no game is currently active.")
         return
     return func(msg, game)
Ejemplo n.º 25
0
def dopenis(msg):
    """Some people like penis too."""
    reply = u"\u2570\u22c3\u256f"
    bot_utils.reply(msg, reply)
Ejemplo n.º 26
0
def getguilds(msg):
    """Print the list of joined guilds"""
    response = bot_utils.HTTP_SESSION.get("/users/@me/guilds")
    for guild in response.json():
        bot_utils.reply(msg, str(guild))
Ejemplo n.º 27
0
def doboobs(msg):
    """Because people keep asking for it..."""
    reply = u"No. There will be no 'butt' command."
    bot_utils.reply(msg, reply)
Ejemplo n.º 28
0
def call(msg):
    """Thought for the day."""
    bot_utils.reply(msg, "Thought for the day: %s" % random.choice(THOUGHTS))