Exemple #1
0
    def handle_chat(self, player, msg, channel):
        message = msg

        if player.clean_name.lower() == 'iouonegirl':
            return #minqlbot.console_command("print i'll ignore waht u said")

        if self.contains(msg, "shit"):
            minqlbot.console_print("'{}'\n".format(msg))
            channel.reply("^7Do you need a SHEET of paper, {}?".format(player.clean_name.lower()))

        elif self.contains(msg, "bitch"):
            strings = ["^7Perhaps you meant to say 'female dog'?",
                "^7I'd love to go to the BEACH right now! How about you, {}?"]
            idx = random.randrange(0, len(strings))
            formatted = strings[idx].format(player.clean_name.lower())
            channel.reply(formatted)

        elif self.contains(msg, "f**k"):
            minqlbot.console_command("print " + player)
            channel.reply("^7Watch your language! GOD sees everything!")

        elif self.contains(msg, "rape"):
            strings = ["^7You call that ^1RAPE^7? Where I come from we call that tickling!",
                "^7There are NO breaks on the ^1RAPE ^7train!"]
            idx = random.randrange(0, len(strings))
            channel.reply(strings[idx])
Exemple #2
0
    def threadvote(self):

# Code commented because bot vetoed no his own vote -_-
# Don't know why, but if you want to revive this, figure a way to see what the vote is about
# before you shut it down
##        # If some sneaky f****r tries to vote something before us
##        if self.is_vote_active():
##            self.vote_no()
##            self.currmap = self.nextmap
##            self.changemap(self.nextmap)
##            self.thread.stop()
##            self.thread = None
##            return

        # Grey area where we don't know if voting is allowed yet...
        minqlbot.console_command("callvote map {}".format(self.nextmap))
        time.sleep(1)
        if self.is_vote_active(): #or self.nextmap == self.currmap:
            self.thread.stop()
            self.debug("I could callvote the map!")
            self.currmap = self.nextmap
            self.nextmap = None
            self.thread = None
            self.vote_yes()
            return

        # If we couldnt cast this vote yet try again
        self.debug("Trying again to change map in 3 seconds")
        time.sleep(3)
        self.threadvote()
Exemple #3
0
    def cmd_dance(self, player, msg, channel):
        minqlbot.console_print("'good game!'\n") # komt in console
        minqlbot.console_command("print good game!") # komt in text fields
        if self.score_backup is None:
            return
        min_score = 999
        min_player = "999"

        minqlbot.console_print("--{}!".format(self.score_backup)) # komt in text fields
        for score in self.score_backup:
            if score.score > min_score:
                continue
            min_score = score.score
            min_player = score.player.clean_name

        #minqlbot.console_print("[*] dudududududu!") # komt in text fields
        channel.reply("^7.{} has lowest score: {}".format(score.player.clean_name, score.score))
Exemple #4
0
    def handle_game_end(self, game, score, winner):
        if not self.plugin_active:
            return

        if self.usualnext:
            poolname = POOLS[POOL_REGULAR]
            #activecount = len(self.active_regular) # non-db version(older)
            activecount = self.getactivecount(POOL_REGULAR)
            if activecount == 0:
                self.cmd_resetmaps(None, [None, poolname], None)
            if activecount == 0:
                return self.msg("^7No regular maps selected. Please contact a server admin about this issue.")
            #idx = random.randint(0, activecount-1)
            # self.nextmap = self.active_regular.pop(idx) # older
            self.nextmap = self.getnextactive(POOL_REGULAR)

        else:
            poolname = POOLS[POOL_IRREGULAR]
            #activecount = len(self.active_irregular) # non-db version(older)
            activecount = self.getactivecount(POOL_IRREGULAR)
            if activecount == 0:
                self.cmd_resetmaps(None, [None, poolname], None)
            if activecount == 0:
                return self.msg("^7No irregular maps selected. Please contact a server admin about this issue.")
            #idx = random.randint(0, activecount-1)
            #self.nextmap =  self.active_irregular.pop(idx)
            self.nextmap = self.getnextactive(POOL_IRREGULAR)

        self.usualnext = not self.usualnext
        self.delay(6, lambda: self.msg("^7Next {} map: ^6{}^7!".format(poolname, self.nextmap)))
        self.currmap = self.game().short_map

        # vote 1 (which is the map we just played i think
        minqlbot.console_command("vote 1")

        # Reset skippers
        self.skippers = []

        # start the thread OPTIONAL TODO DELAY THIS A BIT
        self.thread = threading.Thread(target=self.threadvote)
        self.delay(15, lambda: self.thread.start())
        self.debug("Map Thread starts in 15s")
        return
Exemple #5
0
    def handle_game_end(self, game, score, winner):

        #self.msg("^7Top {} useful damages:".format(min(len(self.scores_usefull), TOP)))

        strings = ["1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th", "10th", "11th", "12th", "13th", "14th"]

        says = []

        # List the minimum of the topsize and the amount of players
        for i in range(min(len(self.scores_usefull), TOP)):

            # If there are no more players left, break
            if len(self.scores_usefull) == 0:
                break

            # Otherwise pop the next name with highest damage
            name = max(self.scores_usefull, key=lambda el: self.scores_usefull[el][1])
            team, dmg = self.scores_usefull.pop(name)
            tc = self.get_team_color(team)

            # Tell players how many more matches they need to play before recording top scores
            games_completed = self.get_completed_matches(name) + 1 # cached is 1 match behind
            if games_completed == COMPLETED_MATCHES:
                player_ = self.find_player(name)
                if player_:
                    player_.tell("You've completed enough matches to contest for highest damage! Good luck!")
                else:
                    minqlbot.console_command("Tell {} You've completed enough matches to contest for highest damage! Good luck!".format(name))
            elif games_completed < COMPLETED_MATCHES:
                left = COMPLETED_MATCHES - games_completed
                player_ = self.find_player(name)
                if player_:
                    player_.tell("You need to complete {} more matches before your top scores are recorded.".format(left))
                else:
                    minqlbot.console_command("Tell {} You need to complete {} more matches before your top scores are recorded.".format(name, left))
            # Wipe the match caches because they wouldnt be accurate anymore
            self.cache_completed.clear()
Exemple #6
0
 def cmd_exit(self, player, msg, channel):
     """Makes the bot clean up and stop functioning."""
     minqlbot.console_command("bot exit")
Exemple #7
0
    def handle_scores(self, scores):

        # Update scores
        self.scores_live = scores

        # If there is no flag set, it's not the end of a round yet
        if not self.flag:
            return

        winner = self.flag
        losers = 'redblue'.replace(winner, '')

        self.flag = '' # Reset flag for next time

        # Calculate if we are in a special case
        amount_of_rounds = (self.game().red_score + self.game().blue_score)
        special_case =  (self.scores_snapshot == {}) and (amount_of_rounds > 1)
        # After the loop that creates the snapshot is done, end the calculations

        if LIST_ALL_CONSOLE:
            minqlbot.console_print("^7> Round ended. Here are the damage results:\n")

        # Store the current damage differences from this round in this dict
        round_diffs = []

        # Store the messages for personal damages, so we can display it after the lowest-highest message
        personal_messages = []

        # This loop will create the snapshot of the round scores/damages for next round
        for s in self.scores_live:

            # ignore players that are not actively playing
            if s.team not in ['red', 'blue']:
                continue

            # Iteration variables
            name = s.player.clean_name.lower()
            team = s.team
            prev_dmg = self.get_player_score(name)
            curr_dmg = s.damage_done
            diff = curr_dmg - prev_dmg
            tc = self.get_team_color(team)
            matches_completed = self.get_completed_matches(name)
            bool_matches_required = matches_completed >= COMPLETED_MATCHES

            if LIST_ALL_CONSOLE:
                minqlbot.console_print("^7> ^{}{}^7: {} damage\n".format(tc, name, diff))

            # Make sure the player is known in the usefull damages counter, starting with 0.
            # Partly to evade a try/catch statement, partly so 0 damages can be shown
            if not self.scores_usefull.get(name):
                self.scores_usefull[name] = [team, 0]

            # If the player is in the winning team, count the usefull damage for after the game
            # and it's not the special case, because it wouldnt be fair to the players
            # that won the round just after the plugin was restarted
            if team == winner and not special_case:
                val = self.scores_usefull[name]
                previous_usefull_damage = val[1]

                # Note that this sets the team to where the user is in now.
                # If he switched teams, the usefull damage will be switched with him
                self.scores_usefull[name] = [winner, previous_usefull_damage + diff]

            # Store the difference for calculations after the iteration
            # Handicapped people need to have their differences recalculated.
            diff = self.calculate_handicap(diff, max(s.player['hc'], self.handicaps[name]))

            round_diffs.append([name, team, diff, bool_matches_required])
            # Add it to the snapshot to compare it to the next time.
            self.scores_snapshot[name] = [team, curr_dmg]


        # SPECIAL CASE: plugin was reloaded during a game:
        # scores snapshot would have been empty, but it wasn't be the first round
        if special_case:
            # Ignore this round because the game is on and plugin was reloaded
            self.msg("^7Skipping damage calculations since plugin was restarted mid-game...")
            # But do save the current scores for the next end of round:
            return

        # Now iterate over differences to find greatest and lowest values
        lowest_names = []
        lowest_dmg = 9000
        highest_names = []
        highest_dmg = -1

        round_diffs.sort(key=lambda el: el[2], reverse = True) # sort on damage high>low

        # Find highest damage doers for winning team
        for record in round_diffs:
            name, team, diff, bool_matches_required = record
            tc = self.get_team_color(team)

            # Highest damage doer for winning team:
            if team == winner and diff > highest_dmg:
                highest_names = [[tc,name]]
                highest_dmg = diff
            elif team == winner and diff == highest_dmg:
                highest_names.append([tc,name])

            # Lowest from losing team
            if team == losers and diff < lowest_dmg:
                lowest_names = [[tc,name]]
                lowest_dmg = diff
            elif team == losers and diff == lowest_dmg:
                lowest_names.append([tc,name])

            # Also check if the highest damage is a top record for the map
            curr_map = self.game().short_map
            bool_still_space = len(self.top_damages) < 10
            # If there isnt still space, we are able to always get index [-1] (lowest one)
            if (team == winner) and bool_matches_required and (bool_still_space or (diff > self.top_damages[-1]['dmg'])):


                # If we are only here because we are filling this map up (<10)
                # Just insert it and make no big deal about it
                if bool_still_space:
                    self.db_insert_top_damage(name, curr_map, diff)
                    self.top_damages = self.db_get_top_damages(curr_map)
                else:

                    lowest_top = self.top_damages[-1]

                    # Insert into database. If False then not inserted, but continue
                    if not self.db_insert_top_damage(name, curr_map, diff):
                        continue
                    # Remove lowest value
                    # commented out because we'll just accumulate these values in the DB
                    # self.db_remove_top_damage(lowest_top['name'], curr_map, lowest_top['dmg'])
                    # Update the top damages for this map
                    self.top_damages = self.db_get_top_damages(curr_map)

                    for el in self.top_damages:
                        if el['name'] == name and el['dmg'] == diff:
                            pos = self.top_damages.index(el)
                            #self.msg("^7Holy shit! ^2{}^7's damage (^3{}^7) earned position ^2{}^7 in the maptopdmg list!".format(name, diff, pos+1))
                            personal_messages.append("^7Holy shit! ^2{}^7's damage (^1{}^7) earned position ^3{}^7 in the maptopdmg list!".format(name, diff, pos+1))
                            break

            # If winning team (and completed matches required), check if this is a personal best:
            if team == winner and bool_matches_required:
                player_prev_top, mapname = self.db_get_top_damage_for_players(name)
                if player_prev_top > 0 and  diff > player_prev_top:
                    #self.msg("^7New ^2personal^7 record for ^6{}^7: ^3{}^7 useful damage!".format(name, diff))
                    personal_messages.append("^7New personal record for ^3{}^7: ^5{}^7 useful damage!".format(name, diff))


            if self.get_tell_preference(name) == 1:
                self.debug("Trying to tell {} his score({}) ".format(name,diff))
                player_ = self.find_player(name)
                if player_:
                    player_.tell("You have done {} damage this round.".format(diff))
                else:
                    minqlbot.console_command("tell {} You have done {} damage this round.".format(name, diff))


        # If SHOW_LAST_ROUND is turned off and we hit last round, we don't display last message
        if  not SHOW_LAST_ROUND and self.game().roundlimit in self.game().scores:
            return

        # Shame/Praise those people:
        say = "^7Least dmg: {} ({})  --  Most dmg: {} ({})"
        self.msg(say.format(self.pretty_print(lowest_names), lowest_dmg, self.pretty_print(highest_names), highest_dmg))

        # Then display the (personal) messages
        personal_messages.reverse()
        for record in personal_messages:
            self.delay(0.8, self.msg, args=(record,))