Example #1
0
 def post_random_tweet(self):
     session = connect_sql()
     quote = random_quote(session)
     quote.used = True
     session.commit()
     try:
         tweet(quote.to_tweet_string())
     except:
         logging.error("Could not tweet : %s, too long." % quote.to_tweet_string())
     finally:
         session.close()
Example #2
0
    async def on_message(self, msg):
        """Simple on message thing."""

        if "text" in msg:
            if "rpnf" in msg['text'].lower() or "neutron flow" in msg['text'].lower():
                await self.sender.sendMessage(utils.random_quote("doctorwho"), parse_mode="Markdown")

            if "force_burns" in msg['text'].lower() or "these are not the droids you are looking for" in msg['text'].lower():
                await self.sender.sendMessage(random_quote("starwars"), parse_mode="Markdown")

            if "codeme" in msg['text'].lower():
                await self.sender.sendMessage(
                    "I know naafing, code me: https://github.com/nasfarley88/west313-bot")

            if "#officesoundtrack" in msg['text'].lower():
                await self.add_to_office_soundtrack(msg)

            if "/playitagain" in msg['text'].lower():
                with dataset.connect(config.DBASE_LOCATION) as db:
                    office_soundtrack_table = db['office_soundtrack']
                    await self.sender.sendMessage(random.choice(list(office_soundtrack_table.all()))['url'])

            if "/deleteentry" in msg['text'].lower():
                await self.delete_entry(msg)

            if "/spike" in msg['text'].lower():
                await self.sender.sendMessage("Tracing...")
                await asyncio.sleep(random.random()*6)
                await self.sender.sendMessage("Your IP is: {}.{}.{}.{}".format(
                    random.randint(1,127),
                    random.randint(1,127),
                    random.randint(1,127),
                    random.randint(1,127)
                ))
                await self.sender.sendChatAction("typing")
                await asyncio.sleep(random.random()*2+0.5)
                await self.sender.sendMessage("Better luck next time.")
Example #3
0
def run_command(message_data):
    sender = message_data['sender']
    said = message_data['said']
    # '#channel' if room, 'sender' if private message
    current_channel = message_data['current_channel']
    params = message_data['params']

    # Get title from web pages
    if 'http://' in said:
        url = extract_url(said)
        title = get_title(url)
        if title:
            say(current_channel, 'Title: %s' % title)

    # Get link to Wikipedia article
    if '[[' in said:
        for article_name in extract_article(said):
            say(current_channel, get_link(article_name))

    # Reply to mention with a random quote
    if nickname in said:
        say(current_channel, random_quote(sender))

    ## IRC commands ##
    search_term = '+'.join(params)
    
    # List all commands
    if said.find('@help') == 0:
        say(sender, 'Search engines: google, wa, ddg, drae, dpd, en, es')
        say(sender, 'Misc: random [list], conv (unit) to (unit), fetch (wikipedia_article), link <start|get|check|stop>, calc (expression)')

    # Google
    elif said.find('@google') == 0:
        say(current_channel, 'https://www.google.com/search?q=%s' % search_term)

    # Wolfram Alpha
    elif said.find('@wa') == 0:
        say(current_channel, 'http://www.wolframalpha.com/input/?i=%s' % search_term)

    # DuckDuckGo
    elif said.find('@ddg') == 0:
        say(current_channel, 'http://duckduckgo.com/?q=%s' % search_term)

    # DRAE
    elif said.find('@drae') == 0:
        say(current_channel, 'http://lema.rae.es/drae/?val=%s' % search_term)

    # DPD
    elif said.find('@dpd') == 0:
        say(current_channel, 'http://lema.rae.es/dpd/?key=%s' % search_term)

    # Jisho kanji lookup
    elif said.find('@kan') == 0:
        escaped_term = urllib2.quote(search_term)
        say(current_channel, 'http://jisho.org/kanji/details/%s' % escaped_term)

    # EN > JP
    elif said.find('@ei') == 0:
        say(current_channel, 'http://jisho.org/words?jap=&eng=%s&dict=edict' % search_term)

    # JP > EN
    elif said.find('@ni') == 0:
        escaped_term = urllib2.quote(search_term)
        say(current_channel, 'http://jisho.org/words?jap=%s&eng=&dict=edict' % escaped_term)

    # EN > ES
    elif said.find('@en') == 0:
        say(current_channel, 'http://www.wordreference.com/es/translation.asp?tranword=%s' % search_term)

    # ES > EN
    elif said.find('@es') == 0:
        say(current_channel, 'http://www.wordreference.com/es/en/translation.asp?spen=%s' % search_term)

    # Random choice
    elif said.find('@random') == 0:
        if len(params) == 1:
            say(current_channel, 'f****t')
        elif len(params) > 1:
            say(current_channel, random.choice(said.split(',').strip()))
        else:
            say(current_channel, random.choice([0, 1]))

    # Unit converter
    elif said.find('@conv') == 0:
        if 'to' not in params:
            return
        index = params.index('to')
        amount = params[0]
        unit_from = params[1:index]
        unit_from = urllib2.quote(' '.join(unit_from))
        # 'to' == params[index]
        unit_to = params[index + 1:]
        unit_to = urllib2.quote(' '.join(unit_to))

        conversion_url = 'http://www.google.com/ig/calculator?hl=en&q='

        conversion = fetch_url(conversion_url + amount + unit_from + '=?' + unit_to).read()
        parsed_conversion = conversion.split('"')

        # Check for errors
        if len(parsed_conversion[5]) == 0:
            unit_result = urllib2.unquote(unit_to)
            say(current_channel, '%s %s' % (parsed_conversion[3].split()[0], unit_result))

    # Linkrace module
    elif said.find('@link') == 0:
        # Get race links
        if params[0] == 'get':
            url = 'http://es.wikipedia.org/wiki/%s'
            start, end = random_pair()
            starturl = url % urllib2.quote(start)
            endurl = url % urllib2.quote(end)
            say(current_channel, 'Start article is %s' % starturl)
            say(current_channel, 'Goal article is %s' % endurl)

        # Check if chain is valid
        elif params[0]  == 'check':
            chain = ' '.join(params[1:])
            broken_links = check_chain(chain)
            if not broken_links:
                say(current_channel, 'The chain is valid.')
            else:
                error_list = ' | '.join(broken_links)
                say(current_channel, error_list)
                say(current_channel, 'The chain is not valid.')

    # Calculator
    elif said.find('@calc') == 0:
        expression = ''.join(params)
        result = str(calculate(expression))
        say(current_channel, result)

    # Wikipedia fetch
    elif said.find('@fetch') == 0:
        article_name = ' '.join(params)
        extract = fetch(article_name)
        say(current_channel, extract)

    # Text game
    elif said.find('@dicks') == 0:
        global game
        # Commands available for everyone
        if params[0] == 'join':
            game.join_game(sender)
        elif params[0] == 'players':
            say(current_channel, [player.name for player in game.players])
        # Commands available for players
        if sender in [player.name for player in game.players]:
            if params[0] == 'panel':
                panel_url = sprunge(game.panel(sender))
                say(sender, '[i] Uploading panel')
                say(sender, panel_url)
            elif params[0] == 'settle':
                group = params[1]
                game.settle(sender, group)
            elif params[0] == 'move':
                troop = params[1]
                new_position = [params[2], params[3]]
                game.move(sender, troop, new_position)
    
    ## Owner commands ##
    if sender == owner:
        # Disconnect
        if said == '.quit':
            execute('QUIT')
            sys.exit(0)
        
        # Send message from bot
        elif said.find('.say') == 0:
            if len(params) > 1:
                say(params[0], ' '.join(params[1:]))

        # Print userlist
        elif said.find('.users') == 0:
            say(current_channel, str(users))

        # Bot joins
        elif said.find('.join') == 0:
            channel = params[0]
            execute('JOIN %s' % channel)

        # Bot parts
        elif said.find('.part') == 0:
            execute('PART %s' % current_channel)
            del users[current_channel]

        # Bot kicks
        elif said.find('.kick') == 0:
            user = params[0]
            reason = ' '.join(params[1:])
            if not reason:
                reason = 'huh'
            bot_kick(current_channel, user, reason)
Example #4
0
def run_command(message_data):
    sender = message_data["sender"]
    full_text = message_data["full_text"]
    # "#channel" if room, "sender" if private message
    channel = message_data["channel"]
    command = message_data["command"]
    args = message_data["args"]

    def cringe_words(message):
        for w in ["xd", "spic", "cring", "derail"]:
            if w in "".join(c for c in "".join(message.lower().split())
                            if c.isalpha()):
                return True
        return False

    if sender == "eyy" and cringe_words(full_text):
        execute("KICK #bogota eyy ebin")

    # Refuse to do anything if not well fed by the users
    """
    if not food.enough(sender):
        message_queue.add("nah")
        return
    """

    # Reply to mention with a random quote
    if config.nickname in full_text and sender != config.nickname:
        message_queue.add(channel, random_quote(sender))

    # Give bux to users
    bank.make_money(sender, full_text)

    if not command:
        return

    elif command == "help":
        message_queue.add(
            sender,
            "Grass: grass-new (chip-value), grass-start, grass-join, gr, gb (amount), gp, gs, grass-cancel"
        )
        message_queue.add(
            sender,
            "Slots: slot-chips (amount), easy-slot <auto>, hard-slot <auto>, slot-stop, slot-cashout"
        )
        message_queue.add(
            sender,
            "Misc: pick [list], roll (number), ask (query), fetch (wikipedia_article), calc (expression), bux, sendbux (user) (amount), sharia (target) (amount)"
        )

    # Random choice
    elif command == "pick":
        if len(args) > 1:
            message_queue.add(channel, random.choice(args))

    # Die roll
    elif command == "roll":
        if not args:
            max_roll = 6
        elif len(args) == 1 and args[0].isdigit():
            max_roll = int(args[0])

        message_queue.add(channel, random.randint(1, max_roll))

    # Wolfram Alpha query
    elif command == "ask":
        response = wolfram.ask(" ".join(args))
        message_queue.add(channel, response)

    # Calculator
    elif command == "calc":
        expression = ''.join(args)
        result = str(calculate(expression))
        message_queue.add(channel, result)

    # Wikipedia fetch
    elif command == "fetch":
        article_name = ' '.join(args)
        extract = wikipedia.fetch(article_name)
        message_queue.add(channel, extract)

    # Check balance
    elif command == "bux":
        amount = bank.ask_money(sender)
        message_queue.add(channel,
                          "{} has {:.2f} newbux".format(sender, amount))

    # Transfer money
    elif command == "sendbux":
        if len(args) != 2:
            message_queue.add(channel, "eh")
            return
        source, destination, amount = sender, args[0], args[1]
        if not is_number(amount):
            message_queue.add(source, "numbers please")
            return
        bank.transfer_money(source, destination, float(amount))

    # Redistribute wealth
    elif command == "sharia":
        if len(args) != 2:
            message_queue.add(channel, "eh")
            return
        source, target, amount = sender, args[0], args[1]
        if not is_number(amount):
            message_queue.add(source, "numbers please")
            return
        bank.islamic_gommunism(source, target, float(amount), channel, users)

    # Grass game
    elif command == "grass-new":
        if len(args) < 1:
            message_queue.add(channel, "how much for each chip")
            return
        chip_value = args[0]
        if not is_number(chip_value):
            message_queue.add(source, "numbers please")
            return
        grass.new_game(sender, channel, float(chip_value))

    elif command == "grass-join":
        grass.add_player(sender, channel)

    elif command == "grass-start":
        grass.start(sender, channel)

    elif command == "gr":
        grass.play(sender, channel)

    elif command == "gb":
        if len(args) < 1:
            message_queue.add(channel, "how much are you betting")
            return
        bet = args[0]
        if not is_number(bet):
            message_queue.add(channel, "numbers please")
            return
        grass.bet(sender, bet, channel)

    elif command == "gp":
        grass.pass_turn(sender, channel)

    elif command == "gs":
        grass.print_chips(channel)

    elif command == "grass-cancel":
        grass.abort(channel)

    # Slot machine
    elif command == "slot-chips":
        if len(args) < 1:
            message_queue.add(channel, "how many are you buying")
            return
        amount = args[0]
        if not is_number(amount):
            message_queue.add(channel, "numbers please")
            return
        slots.buy_chips(sender, channel, int(amount))

    elif command == "easy-slot":
        auto = False
        if len(args) == 1 and args[0] == "auto":
            auto = True
        slots.start(sender, channel, slots.Games.EASY, auto=auto)

    elif command == "hard-slot":
        auto = False
        if len(args) == 1 and args[0] == "auto":
            auto = True
        slots.start(sender, channel, slots.Games.HARD, auto=auto)

    elif command == "slot-stop":
        slots.stop(sender, channel)

    elif command == "slot-cashout":
        slots.cash_out(sender, channel)

    ## Owner commands ##
    if sender == config.owner:
        # Disconnect
        if command == "quit":
            execute("QUIT")
            sys.exit(0)

        # Send message from bot
        elif command == "say":
            if len(args) > 1:
                message = ' '.join(args[1:])
                message_queue.add(args[0], message)

        # Print userlist
        elif command == "users":
            message_queue.add(channel, str(users))

        # Bot joins
        elif command == "join":
            channel = args[0]
            execute("JOIN %s" % channel)

        # Bot parts
        elif command == "part":
            execute("PART %s" % channel)
            del users[channel]

        # Bot kicks
        elif command == "kick":
            user = args[0]
            reason = " ".join(args[1:])
            if not reason:
                reason = "huh"
            bot_kick(channel, user, reason)

        # Module reloads
        elif command == "reload":
            module_name = args[0]
            importlib.reload(sys.modules[module_name])
            message_queue.add(channel, "aight")