Beispiel #1
0
def write_tweet_ops(bot, trigger):
    """Allows a channel operator to post a tweet manually."""
    if len(trigger.group(2)) > 140:
        bot.reply('Your tweet is too f*****g long! 140 characters or less!')
    else:
        api.PostUpdate(trigger.group(2))
        bot.reply('Your tweet has been posted. Say .toptweet to verify.')
Beispiel #2
0
def list_locations(bot, trigger):
    bot.reply(
        "There are many weird and wonderful places in Shit Foot Mongo Land, I have sent you them in a private message"
    )
    count = 0
    for location in locations:
        bot.say(str(count + 1) + ": " + locations[count], trigger.nick)
        count += 1
Beispiel #3
0
def get_record(bot, trigger):
    wins = bot.playerdb.get_nick_value(trigger.nick, "wins")
    losses = bot.playerdb.get_nick_value(trigger.nick, "losses")
    if wins is None and losses is None:
        bot.reply("You haven't had any fights yet, you kind soul!")
    else:
        if wins is None:
            wins = 0
        if losses is None:
            losses = 0
        bot.reply("Your record is " + str(wins) + ":" + str(losses))
Beispiel #4
0
def get_stats(bot, trigger):
    #use balance to check if valid player
    balance = bot.playerdb.get_nick_value(trigger.nick, "balance")
    if balance is None:
        bot.reply("You are not part of the game :(")
    else:
        attack = bot.playerdb.get_nick_value(trigger.nick, "attack")
        defense = bot.playerdb.get_nick_value(trigger.nick, "defense")
        if attack is None:
            attack = 50
        if defense is None:
            defense = 50
        bot.reply("Your attack is " + str(attack) + " and your defense is " +
                  str(defense))
Beispiel #5
0
def propose_tweet(bot, trigger):
    """Stores a proposed tweet and associated files in /var/www/py/tweets."""
    if not trigger.group(2):
        return bot.reply('To use this properly you gotta say ".tweetpropose <tweet>"')
    if len(trigger.group(2)) > 140:
        bot.reply('Your tweet is too f*****g long! 140 characters or less!')
    sequence = ""
    userList = bot.users
    userListPreOut = len(userList)
    userListOut = int(userListPreOut) - 2
    userName = trigger.nick
    tweet_file = "/var/www/py/tweets/tweet%s.txt"
    tweetPop = "/var/www/py/tweets/tweet%s.pop"
    tweetVoteCount = "/var/www/py/tweets/tweet%s.cnt"
    tweetLog = "/var/www/py/tweets/tweet%s.log"
    while isfile(tweetVoteCount % sequence):
        sequence = int(sequence or "1") + 1
    tweetVoteCount = tweetVoteCount % sequence
    initWriteTweetVoteCount = open(tweetVoteCount, 'w')
    initWriteTweetVoteCount.close()
    writeTweetVoteCount = open(tweetVoteCount, 'r+')
    writeTweetVoteCount.write('0')
    while isfile(tweet_file % sequence):
        sequence = int(sequence or "1") + 1
    tweet_file = tweet_file % sequence
    initialize_tweet = open(tweet_file, 'w')
    initialize_tweet.close()
    new_tweet = open(tweet_file, 'r+')
    new_tweet.write(str(trigger.group(2)))
    while isfile(tweetPop % sequence):
        sequence = int(sequence or "1") + 1
    tweetPop = tweetPop % sequence
    initWriteTweetPop = open(tweetPop, 'w')
    initWriteTweetPop.close()
    writeTweetPop = open(tweetPop, 'r+')
    writeTweetPop.write(str(userListOut))
    while isfile(tweetLog % sequence):
        sequence = int(sequence or "1") + 1
    tweetLog = tweetLog % sequence
    initWriteTweetLog = open(tweetLog, 'w')
    initWriteTweetLog.close()
    writeTweetLog = open(tweetLog, 'r+')
    writeTweetLog.write('Tweet proposed by ' + userName)
    bot.reply('Your tweet has been logged. Every 45 minutes I will ask for a vote from the room.')
Beispiel #6
0
def explore_location(bot, trigger):
    location = int(trigger.group(2)) - 1

    #check they haven't already explored this hour
    lastExploreTime = bot.playerdb.get_nick_value(trigger.nick,
                                                  "lastExploration")
    if lastExploreTime is not None:
        if lastExploreTime > time.time() - 600:
            bot.reply("You're too tired to explore again, chill")
            return

    bot.playerdb.set_nick_value(trigger.nick, "lastExploration",
                                int(time.time()))
    message = monsters[location]
    win = random.randint(0, 100)
    if win < winPercs[location]:
        message += winStrings[location]
        change = 100 / winPercs[location]
    else:
        change = -100 / winPercs[location]
        message += loseStrings[location]

    #chance of stat change related to difficulty
    if random.randint(0, 100) > winPercs[location]:
        message += "Your stats have been affected: "
        #50\50 attack or defense
        if random.randint(0, 1) == 0:
            stat = "attack"
        else:
            stat = "defense"
        message += str(stat) + " "
        current = int(bot.playerdb.get_nick_value(trigger.nick, stat))
        bot.playerdb.set_nick_value(trigger.nick, stat, current + change)
        message += str(change)

    if random.randint(0, 100) > winPercs[location]:
        message += " Your balance has been affected: "
        balance = int(bot.playerdb.get_nick_value(trigger.nick, "balance"))
        bot.playerdb.set_nick_value(
            trigger.nick, "balance",
            int(balance) + int(change / abs(change) *
                               (100 - winPercs[location])))
        message += str(change / abs(change) * (100 - winPercs[location]))
    bot.reply(message)
Beispiel #7
0
def fight(bot, trigger):
    attackerBalance = bot.playerdb.get_nick_value(trigger.nick, "balance")
    if attackerBalance is None:
        bot.reply("You are not part of the game :(")
        return
    defenderBalance = bot.playerdb.get_nick_value(trigger.group(1), "balance")
    if defenderBalance is None:
        bot.reply(trigger.group(1) + " is not part of the game :(")
        return

    if trigger.nick == trigger.group(1):
        bot.reply("You hurt yourself and lost one sf::Token")
        bot.playerdb.set_nick_value(trigger.nick, "balance",
                                    int(attackerBalance) - 1)
        return

    #check they haven't already fought in the last 5 mins
    lastFightTime = bot.playerdb.get_nick_value(trigger.nick, trigger.group(1))
    if lastFightTime is not None:
        if lastFightTime > time.time() - 300:
            bot.reply("Don't be such a bully")
            return

    bot.playerdb.set_nick_value(trigger.nick, trigger.group(1), time.time())

    attackerAttack = bot.playerdb.get_nick_value(trigger.nick, "attack")
    if attackerAttack is None:
        attackerAttack = 50
        bot.playerdb.set_nick_value(trigger.nick, "attack", attackerAttack)
    defenderDefense = bot.playerdb.get_nick_value(trigger.group(1), "defense")
    if defenderDefense is None:
        defenderDefense = 50
        bot.playerdb.set_nick_value(trigger.group(1), "defense",
                                    defenderDefense)
    result = random.randint(0, int(attackerAttack) + int(defenderDefense))
    if result < attackerAttack:
        winner = trigger.nick
        loser = trigger.group(1)
    else:
        winner = trigger.group(1)
        loser = trigger.nick
    bot.say(winner + " was victorious! They won 1 sf::Token from " + loser)
    winnerbalance = bot.playerdb.get_nick_value(winner, "balance")
    loserbalance = bot.playerdb.get_nick_value(loser, "balance")
    bot.playerdb.set_nick_value(winner, "balance", winnerbalance + 1)
    bot.playerdb.set_nick_value(loser, "balance", loserbalance - 1)
    winnerWins = bot.playerdb.get_nick_value(winner, "wins")
    loserLosses = bot.playerdb.get_nick_value(loser, "losses")
    if winnerWins is None:
        winnerWins = 0
    if loserLosses is None:
        loserLosses = 0
    bot.playerdb.set_nick_value(winner, "wins", int(winnerWins) + 1)
    bot.playerdb.set_nick_value(loser, "losses", int(loserLosses) + 1)
Beispiel #8
0
def vote_on_tweet(bot, trigger):
    """Allows users to vote on a selected tweet."""
    if not trigger.group(2):
        bot.reply('Vote for WHICH tweet?')
    tweetNumber = trigger.group(2)
    userName = trigger.nick
     #opens tweet#
    selectedTweet = '/var/www/py/tweets/tweet' + str(tweetNumber) + '.txt'
    voteLog = '/var/www/py/tweets/tweet' + str(tweetNumber) + '.log'
    votePopFile = '/var/www/py/tweets/tweet' + str(tweetNumber) + '.pop'
    voteCount = '/var/www/py/tweets/tweet' + str(tweetNumber) + '.cnt'
    # the following section needs repair
        #  it is supposed to check whether the nick already appears
        # if it is already appears, it is supposed to prevent the vote
    with open(voteLog, 'a+') as logVote:
        voterLog = logVote.read()
        if voterLog.find(userName) != -1:
            bot.reply('You have already voted or you proposed this f*****g tweet, you cheat!')
        else:
            logVote.write('\n' + userName)
            with open(voteCount, 'r+') as voting:
                rawVoteCnt = [line.rstrip('\n') for line in voting]
                for line in rawVoteCnt:
                    currentCount = int(line)
                    currentCount += 1
                    voting.write(str(currentCount))
    with open(selectedTweet, 'r+') as f:
        rawTweetCnts = [line.rstrip('\n') for line in f]
        for line in rawTweetCnts:
            tweetText = line
    newVoteCount = str(currentCount)
    #checks vote count against userCount
    with open(votePopFile) as f3:
        votePop = f3.readline()
        neededVotes = float(votePop) * 0.8
        if neededVotes < int(currentCount):
            approved_tweet = True
        else:
            approved_tweet = False
    if approved_tweet != True:
        bot.reply('Your vote has been cast for tweet #' + str(tweetNumber) + '. Tweet currently has ' + str(newVoteCount) + ' votes.')
    elif approved_tweet is True:
        bot.reply('Your vote has allowed ' + str(tweetNumber) + '-- "' + str(tweetText) + '" --' + 'to be posted at http://twitter.com/realWoodcoin')
        api.PostUpdate(tweetText)
        bot.say('To check latest tweet, use .toptweet')
        logdate = str(datetime.date.today().strftime("%j"))
        lognow = str(datetime.datetime.now().strftime("%H%M"))
        if not os.path.exists('/var/www/py/tweets/archived/' + logdate):
            os.mkdir('/var/www/py/tweets/archived/' + logdate)
        shutil.move(selectedTweet, '/var/www/py/tweets/archived/' + logdate + '/' + tweetNumber + '-' + lognow + '.txt')
        shutil.move(voteLog, '/var/www/py/tweets/archived/' + logdate + '/' + tweetNumber + '-' + lognow + '.log')
        shutil.move(votePopFile, '/var/www/py/tweets/archived/' + logdate + '/' + tweetNumber + '-' + lognow + '.pop')
        shutil.move(voteCount, '/var/www/py/tweets/archived/' + logdate + '/' + tweetNumber + '-' + lognow + '.cnt')
Beispiel #9
0
def invite(bot, trigger):
    """To new members that are looking for an invitation"""
    joinedTime = bot.db.get_nick_value(trigger.nick,
                                       'join_channel_' + trigger.sender)
    if joinedTime is None:
        logger.error("no join time for nick %s in channel %s", trigger.nick,
                     trigger.sender)
        return

    now = time.time()
    diff = now - joinedTime
    if diff >= 3600:
        logger.info("join time %f for nick %s in channel %s exceeds limit",
                    joinedTime, trigger.nick, trigger.sender)
        return

    bot.reply("If you would like an invite to lobste.rs, please look "
              "at the chat FAQ first. Thank you. https://lobste.rs/chat "
              "(I am a bot. (v).v.(v))")
Beispiel #10
0
def give_tokens(bot, trigger):
    if int(trigger.group(2)) == 0:
        bot.reply("Are you mugging me off?")
    if trigger.nick == trigger.group(1):
        bot.reply("You sf::Muppet")
        return
    giverBalance = bot.playerdb.get_nick_value(trigger.nick, "balance")
    if giverBalance is None:
        bot.reply("You aren't part of the game :(")
        return
    receiverBalance = bot.playerdb.get_nick_value(trigger.group(1), "balance")
    if receiverBalance is None:
        bot.say(trigger.group(1) + " is not part of the game :(")
        return
    if int(trigger.group(2)) > int(giverBalance):
        bot.reply("you wish you had that many sf::Tokens")
        return
    bot.say(trigger.nick + " has generously given " + trigger.group(1) + " " +
            trigger.group(2) + " sf::Tokens")
    bot.playerdb.set_nick_value(trigger.group(1), "balance",
                                receiverBalance + int(trigger.group(2)))
    bot.playerdb.set_nick_value(trigger.nick, "balance",
                                giverBalance - int(trigger.group(2)))
Beispiel #11
0
def peterson(bot, trigger):
    """Link to FAQ if Peterson is mentioned"""
    bot.reply(
        "The site has nothing to do with Jordan Peterson: https://lobste.rs/about#michaelbolton"
    )
Beispiel #12
0
def buy_shit(bot, trigger):
    bot.reply("Haha you can't buy stuff")
Beispiel #13
0
def check_balance(bot, trigger):
    balance = bot.playerdb.get_nick_value(trigger.nick, "balance")
    if balance is None:
        bot.reply("Headshoe pic plz...")
    else:
        bot.reply("Your balance is " + str(balance) + " sf::Tokens")