| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- import random
- from common import font, queries
- from commands.common import CommandHelpers as CH
- from commands.common import GameHelpers
- def do_command(self, connection, event, user, channel):
- cmdtype, trigger, command, replyto = CH.disect_command(self, event)
- # Do nothing if it's not a type of command.
- if not cmdtype:
- return
- # Do nothing if there is no command.
- if not command:
- return
- # The first word of the command sting with arguments, is just the command without arguments.
- try:
- one = command.split()[0] # Get raw command.
- except:
- return
- # Do noting if the games channel function is off and it's a channel message.
- if event.target != connection.get_nickname(): # Command issued to channel.
- if not queries.get_channel_setting_games_commands(self, channel.id): # Games are turned off in channel settigns.
- return # Do nothing.
- if command == 'cmd' or command == 'cmds' or command == 'commands':
- if cmdtype == 'cmd':
- connection.privmsg(replyto, '%sGames: %s%s%s%s%s%s' % (font.grey, CH.ccc(self, "player"), CH.ccc(self, "players"), CH.ccc(self, "levelup") ,CH.ccc(self, "givecoin"), CH.ccc(self, "8ball"), CH.ccc(self, "dice")[:-2]))
- connection.privmsg(replyto, font.grey + "Game help: " + font.blue + self.network.help_character + "level" + font.grey + ", " + font.blue + self.network.help_character + "xp" + font.grey + ", " + font.blue + self.network.help_character + "ap" + font.grey + ", " + font.blue + self.network.help_character + "coin" + font.grey + ", " + font.blue + self.network.help_character + "karma" + font.grey + ".")
- elif one == 'player':
- if len(command.split()) == 1:
- if cmdtype == 'help': # Display help text.
- connection.privmsg(replyto, 'Displays a users game statistics. User optional.')
- connection.privmsg(replyto, 'Usage: %s%s%s%s %snickname' % (font.blue, self.network.command_character, one, font.reset, font.italic))
- return
- message = '%sYour player stats: ' % font.grey
- player_name = event.source.nick
- player = queries.get_user(self, player_name)
- elif len(command.split()) == 2:
- player_name = command.split()[1]
- if cmdtype == 'help':
- connection.privmsg(replyto, 'Displays game stats for player: %s%s' % (font.red, player_name))
- return
- player = queries.get_user(self, player_name)
- if not player:
- connection.action(replyto, 'does not know of a %s%s%s.' % (font.red, trigger.split()[1], font.reset))
- return
- if player_name.lower() == connection.get_nickname().lower():
- connection.privmsg(replyto, "The game does not play the master.")
- return
- message = '%sPlayer stats for %s%s%s: ' % (font.grey, font.red, player.name, font.reset)
- else: # Too many arguments.
- connection.privmsg(replyto, 'Too many arguments, For help type: %s%s%s' % (font.blue, self.network.help_character, one))
- return
- info = GameHelpers.player_info(self, player)
- connection.privmsg(replyto, message + info)
- elif one == 'levelup':
- level, xp, xp_spent, total_xp, karma, coin, coin_spent, coin_given, ap, ap_spent = GameHelpers.get_info(self, user)
- if cmdtype == 'help': #Display help text.
- connection.privmsg(replyto, 'Spend %s XP to gain your next level. Levelup multiple levels by adding an amount.' % str(int(level * 2.7)))
- connection.privmsg(replyto, 'Example: %s%s%s 3' % (font.blue, self.network.command_character, one))
- elif cmdtype == "cmd":
- upgrade_count = 1
- if xp < int(level * 2.7):
- connection.privmsg(replyto, "Insufficient XP, you need at least " + str(int(level * 2.7)) + ".")
- return
- elif ap < 1:
- connection.privmsg(replyto, "Insufficient AP, you need at least 1.")
- return
- elif len(command.split()) == 2: # Command with one argument.
- try:
- levels = int(command.split()[1])
- except:
- connection.privmsg(replyto, "Invalid amount.")
- return
- if levels < 1:
- connection.privmsg(replyto, "Invalid amount.")
- return
- upgrade_count = levels # Valid amount.
- elif len(command.split()) >= 3:
- connection.privmsg(replyto, "Too many arguments. For help type " + font.blue + self.network.help_character + "levelup" + font.reset + ".")
- return
- while xp > int(level * 2.7) and ap > 0 and upgrade_count > 0:
- print(upgrade_count)
- queries.levelup_user(self, user.id, int((level + 1) * 2.7))
- level, xp, xp_spent, total_xp, karma, coin, coin_spent, coin_given, ap, ap_spent = GameHelpers.get_info(self, user)
- if upgrade_count < 0:
- connection.privmsg(replyto, 'Exhausted XP or AP before levelup was complete. You are only partially levelled up.')
- info = GameHelpers.player_info(self, user)
- connection.privmsg(replyto, "Your new statistics: " + info)
- elif one == 'givecoin':
- if cmdtype == 'help': #Display help text.
- connection.privmsg(replyto, "Give coins to another player. Amount optional.")
- connection.privmsg(replyto, font.grey + "Usage: " + font.blue + self.network.command_character + "givecoin " + font.reset + font.italic + "user amount")
- elif cmdtype == "cmd":
- if len(command.split()) == 1:
- connection.privmsg(replyto, "Insufficient arguments. For help type " + font.blue + self.network.help_character + "givecoin" + font.reset + ".")
- return
- elif len(command.split()) > 3:
- connection.privmsg(replyto, "Too many arguments. For help type " + font.blue + self.network.help_character + "givecoin" + font.reset + ".")
- return
- elif command.split()[1] == event.source.nick.lower():
- connection.privmsg(replyto, "You already have your own coin. For help type " + font.blue + self.network.help_character + "givecoin" + font.reset + ".")
- return
- elif command.split()[1] == connection.get_nickname() or command.split()[1] == self.network.nickname:
- connection.privmsg(replyto, "I don't need that. If I wanted I could take all your coin and there would be nothing for you to do to stop me....")
- return
- elif len(command.split()) == 3:
- try:
- if float(command.split()[2]) < 0:
- connection.privmsg(replyto, "You clever abuser! The " + font.red + self.network.command_character + font.bold + "give" + font.bold + "coin" + font.reset + " command is not designed for robbing. There will be consequences...")
- queries.punish_user(self, user_id, -3, -1)
- return
- except TypeError:
- connection.privmsg(replyto, "Invalid amount. For help type " + font.blue + self.network.help_character + "givecoin" + font.reset + ".")
- return
- elif event.target == connection.get_nickname(): # Private message
- for channel in self.channels:
- user_present = False
- if command.split()[1] in self.channels[channel].users(): # User is on a channel the bot inhabits.
- user_present = True
- if not user_present:
- connection.privmsg(replyto, font.red + trigger.split()[1] + font.reset + " is not present on any channel I inhabit.")
- return
- else: # Channel message
- if not command.split()[1] in self.channels[event.target].users():
- connection.privmsg(replyto, font.red + trigger.split()[1] + font.reset + " is not present on this channel.")
- return
- level, xp, xpspent, totalxp, karma, coin, coinspent, coingiven, ap, apspent = GameHelpers.get_info(self, user)
- receiver = queries.get_user(self, command.split()[1])
- if level < 1:
- connection.privmsg(replyto, "You need to " + font.blue + self.network.command_character + "levelup " + font.reset + "to be able to give coin.")
- return
- elif coin < 1:
- connection.privmsg(replyto, "You have no coin to give.")
- return
- elif not receiver:
- connection.action(replyto, "does not know of any \"" + font.red + trigger.split()[1] + font.reset + "\".")
- return
- elif receiver.level <= 0:
- connection.privmsg(replyto, font.red + trigger.split()[1] + font.reset + " is not playing the game.")
- return
- #elif receiver.away == True:
- # connection.privmsg(replyto, font.red + trigger.split()[1] + font.reset + "is not here right now.")
- # return
- elif ap < 1:
- connection.privmsg(replyto, "You have no action points.")
- return
- if len(command.split()) == 2:
- queires.cointransfer(self, user_id, command.split()[1])
- elif len(command.split()) == 3:
- if coin < command.split()[2]:
- connection.privmsg(replyto, "You do not have enough coin.")
- return
- queires.cointransfer(self, sender.id, receiver.id)
- info = GameHelpers.player_info(self, sender)
- connection.notice(event.source.nick, "Your new statistics: " + info)
- elif one == 'players':
- if cmdtype == 'help': #Display help text.
- connection.privmsg(replyto, 'Display top player rankings.')
- elif cmdtype == "cmd":
- toplevel = GameHelpers.list_top_players(self, "level")
- topxp = GameHelpers.list_top_players(self, "xp_spent")
- topcoin = GameHelpers.list_top_players(self, "coin")
- if toplevel:
- connection.notice(event.source.nick, "Ranking level: " + toplevel)
- elif topxp:
- connection.notice(event.source.nick, "Ranking experience: " + topxp)
- elif topcoin:
- connection.notice(event.source.nick, "Ranking wealth: " + topcoin)
- else:
- connection.privmsg(replyto, "Nobody is playing the game.")
- elif command.split()[0] == "level":
- if cmdtype == "help": #Display help text.
- connection.privmsg(replyto, "For increasing amounts of XP you can use !levelup to gain a level. As your level increases, things become more difficult, while more capabilities and options are attained.")
- elif command.split()[0] == "xp":
- if cmdtype == "help": #Display help text.
- connection.privmsg(replyto, "XP is earned by using IRC and playing the game, in channels with " + font.red + connection.get_nickname() + font.reset + ". Ask any operator in " + font.red + self.network.home_channel + font.reset + " to add a channel. XP is used to level up, advance classes, as a limit and as a multiplier. Once XP is expended it keeps counting towards your total.")
- elif command.split()[0] == "ap":
- if cmdtype == "help": #Display help text.
- connection.privmsg(replyto, "AP is earned by using IRC and playing the game in channels with " + font.red + connection.get_nickname() + font.reset + ". Ask any operator in " + font.red + self.network.home_channel + font.reset + " to add a channel. AP is expended for every action you take in the game.")
- elif command.split()[0] == "coin":
- if cmdtype == "help": #Display help text.
- connection.privmsg(replyto, "Coin is earned when certain events occur, mostly when other players perform actions. Coin is used to buy items and classes. To give a player coin use " + font.blue + self.network.command_character + "givecoin" + font.reset + ". Coin affects karma.")
- elif command.split()[0] == "karma":
- if cmdtype == "help": #Display help text.
- connection.privmsg(replyto, "Karma is a secret formula, based upon on your IRC events and how you play the game. It does not increase like XP. Some events, skills and items are karma based.")
- elif command.split()[0] == "8ball":
- if cmdtype == "help": #Display help text.
- connection.privmsg(replyto, "Ask a question of the mighty and illusive 8-Ball.")
- connection.privmsg(replyto, font.grey + "Usage: " + font.blue + self.network.command_character + "8ball " + font.reset + font.italic + "question")
- elif cmdtype == "cmd":
- if len(command.split()) < 2: # Command contains only !8ball.
- messages = [
- "Don't forget to ask a question...",
- "Hey, that's not a question!",
- "What would you like to know?",
- "You want me to predict nothing?",
- "Are you intentionally not asking a question?",
- "Ask a question you tease!",
- "You do not seem to grasp this, for help type: " + font.blue + self.network.help_character + "8ball",
- "You will die alone.",
- ]
- connection.privmsg(replyto, random.choice(messages))
- else:
- messages = [
- "Yes.",
- "No.",
- "Affirmative.",
- "No way!",
- "Negative.",
- "Positive.",
- "Correct.",
- "Incorrect.",
- "Likely",
- "Unlikely",
- "Maybe.",
- "Definately!",
- "Perhaps?",
- "Most indubitably.",
- "Does the pope shit in the woods?",
- "When hell freezes over.",
- "Only between 9 and 5.",
- "Only just before you die.",
- font.red + font.bold + "ERROR: " + font.bold + "probability failure.",
- "Ask again later.",
- "I don't know.",
- "Unpredictable.",
- ]
- connection.privmsg(replyto, random.choice(messages))
- elif command.split()[0] == "dice":
- if cmdtype == "help": #Display help text.
- if len(command.split()) != 1:
- return
- connection.privmsg(replyto, "Rolls multiple dices of chosen type. Specifying type or amount is optional.")
- connection.privmsg(replyto, font.grey + "Usage: " + font.blue + self.network.command_character + "dice " + font.reset + font.italic + "amount type")
- connection.privmsg(replyto, font.grey + "Example: " + font.blue + self.network.command_character + "dice " + font.reset + font.italic + "2 d10")
- connection.privmsg(replyto, font.grey + "Note: " + font.reset + "The dice type is specified as a " + font.italic + "d " + font.reset + "followed by the amount of sides.")
- elif cmdtype == "cmd":
- arguments = len(command.split()) - 1
- if arguments == 0:
- connection.privmsg(replyto, str(random.randint(1, 6)) + " & " + str(random.randint(1, 6)) + ".")
- elif arguments == 1:
- try:
- diceamount = int(command.split()[1])
- except ValueError: # Argument is not an integer.
- if command.split()[1].startswith("d"): # Specific dice type.
- try:
- dicetype = int(command.split()[1][1:])
- except ValueError: # "d" not followd by interger.
- connection.privmsg(replyto, "Invalid number or type of dice. For help type: " + font.blue + self.network.help_character + "dice" + font.reset + ".")
- return
- if dicetype < 1:
- connection.action(replyto, "can not create objects with less then one side.")
- else:
- connection.privmsg(replyto, str(GameHelpers.roll_dice(1, dicetype)[0]))
- else: # Argument does not start with "d" and is not an integer.
- connection.privmsg(replyto, "Invalid number or type of dice. For help type: " + font.blue + self.network.help_character + "dice" + font.reset + ".")
- return
- if diceamount < 1:
- connection.privmsg(replyto, "Rolling " + font.bold + "no " + font.reset + "dice.")
- elif diceamount > 10:
- connection.action(replyto, "can not fit that many dice into it's robot hands.")
- else:
- connection.privmsg(replyto, ", ".join(str(rolls) for rolls in GameHelpers.roll_dice(diceamount, 6)) + ".") # Roll x amount of dice.
- elif arguments == 2:
- try:
- diceamount = int(command.split()[1])
- except ValueError: # First argument not an integer.
- connection.privmsg(replyto, "Invalid number of dice. For help type: " + font.blue + self.network.help_character + "dice" + font.reset + ".")
- return
- try:
- dicetype = int(command.split()[2][1:])
- except ValueError: # Second argument not a dice type.
- connection.privmsg(replyto, "Invalid type of dice. For help type: " + font.blue + self.network.help_character + "dice" + font.reset + ".")
- return
- if diceamount < 1:
- connection.privmsg(replyto, "Rolling " + font.bold + "no " + font.reset + "dice.")
- elif diceamount > 10:
- connection.action(replyto, "can not fit that many dice into it's robot hands.")
- elif dicetype < 1:
- connection.action(replyto, "can not create objects with less then one side.")
- elif dicetype > 9999999999 and diceamount > 1:
- connection.action(replyto, "Those dices are so large i can only roll one at a time.")
- else:
- connection.privmsg(replyto, ", ".join(str(rolls) for rolls in GameHelpers.roll_dice(diceamount, dicetype)) + ".") # Roll x amount of x type dice.
- else: # Invalid amount of arguments.
- connection.privmsg(replyto, "Too many arguments. For help type: " + font.blue + self.network.help_character + "dice" + font.reset + ".")
|