common.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. import random
  2. from common import font, queries, userstatus
  3. class CommandHelpers():
  4. def disect_command(self, event):
  5. trigger = event.arguments[0] # Everything the user inputted.
  6. command = trigger[1:].lower() # Command without prefix. = trigger minus first character.
  7. # Determine command type.
  8. if trigger.startswith(self.network.command_character):
  9. cmdtype = 'cmd'
  10. elif trigger.startswith(self.network.help_character):
  11. cmdtype = 'help'
  12. else:
  13. cmdtype = False
  14. # Determine where to reply to.
  15. if event.type == 'pubmsg':
  16. replyto = event.target
  17. elif event.type == 'privmsg':
  18. replyto = event.source.nick
  19. else:
  20. replyto = False
  21. return(cmdtype, trigger, command, replyto)
  22. def ccc(self, command, rights=False, event=False): # Commandlist colour coding and channel rights filter.
  23. if rights:
  24. show = False
  25. if rights["homechan"] == "owner":
  26. if self.channels[self.network.home_channel].is_owner(event.source.nick):
  27. show = True
  28. if rights["homechan"] == "admin":
  29. if self.channels[self.network.home_channel].is_owner(event.source.nick) or self.channels[self.network.home_channel].is_admin(event.source.nick):
  30. show = True
  31. if rights["homechan"] == "oper":
  32. if self.channels[self.network.home_channel].is_owner(event.source.nick) or self.channels[self.network.home_channel].is_admin(event.source.nick) or self.channels[self.network.home_channel].is_oper(event.source.nick):
  33. show = True
  34. if not event.target == self.connection.get_nickname(): # Channel message.
  35. if rights["chan"] == "owner":
  36. if self.channels[event.target].is_owner(event.source.nick):
  37. show = True
  38. if rights["chan"] == "admin":
  39. if self.channels[event.target].is_owner(event.source.nick) or self.channels[event.target].is_admin(event.source.nick):
  40. show = True
  41. if rights["chan"] == "oper":
  42. if self.channels[event.target].is_owner(event.source.nick) or self.channels[event.target].is_admin(event.source.nick) or self.channels[event.target].is_oper(event.source.nick):
  43. show = True
  44. if show:
  45. return font.blue + self.network.command_character + command + font.grey + ", "
  46. else:
  47. return font.blue + self.network.command_character + command + font.grey + ", "
  48. # class AdminHelpers():
  49. # def get_channelfunctions(self, channel):
  50. # #channelfunctions = self.db.one("SELECT autojoin, aggressiveness, join_greeting, statistics_commands, games, chat FROM channels WHERE LOWER(name)=LOWER('" + channel + "') AND network='" + self.network + "'")
  51. # channelfunctions = self.db.one("SELECT autojoin FROM rotbot_channels WHERE LOWER(name)=LOWER('" + channel + "') AND network='" + self.network.id + "'")
  52. # if channelfunctions[0]:
  53. # autojoin = "on"
  54. # else:
  55. # autojoin = "off"
  56. # # if channelfunctions[2]:
  57. # # joingreet = "on"
  58. # # else:
  59. # # joingreet = "off"
  60. # # if channelfunctions[3]:
  61. # # statscmds = "on"
  62. # # else:
  63. # # statscmds = "off"
  64. # # if channelfunctions[4]:
  65. # # games = "on"
  66. # # else:
  67. # # games = "off"""
  68. # # if channelfunctions[5]:
  69. # # chat = "on"
  70. # # else:
  71. # # chat = "off"""
  72. # #return ("autojoin " + font.green + autojoin + font.reset + ", aggressiveness " + font.green + channelfunctions[1] + font.reset + ", join_greeting " + font.green + joingreet + font.reset + ", statistics_commands " + font.green + statscmds + font.reset + ", games " + font.green + games + font.reset + ", chat " + font.green + chat + font.reset + ".")
  73. # return ('autojoin %s %s %s.' % font.green, autojoin, font.reset)
  74. #
  75. # def is_channelfunction(value):
  76. # if value.lower() in ["autojoin", "aggressiveness", "join_greeting", "statistics_commands", "games", "chat"]:
  77. # return True
  78. # else:
  79. # return False
  80. #
  81. # def describe_channelfunction(function):
  82. # if function == "autojoin":
  83. # message = "Join the channel automaticly after connecting."
  84. # elif function == "aggressiveness":
  85. # message = "How to respond to kick, ban and mode events. Options: " + font.blue + "passive" + font.reset + ", " + font.blue + "defense_only" + font.reset + ", " + font.blue + "equal_retalliation" + font.reset + ", " + font.blue + "battlebot" + font.reset + "."
  86. # elif function == "join_greeting":
  87. # message = "Greet users joining the channel on the first few joins, and later on large amounts."
  88. # elif function == "statistics_commands":
  89. # message = "Enable use of statistics commands."
  90. # elif function == "games":
  91. # message = "Enable use of game commands."
  92. # elif function == "chat":
  93. # message = "Respond to and initiate chat."
  94. # else:
  95. # message = "Sorry, this function has no description yet."
  96. #
  97. # return message
  98. #
  99. # def is_aggressiveness(value):
  100. # if value.lower() in ["passive", "defense_only", "equal_retalliation", "battlebot"]:
  101. # return True
  102. # else:
  103. # return False
  104. class GameHelpers():
  105. def roll_dice(amount, type):
  106. rolls = []
  107. for iterations in range(amount):
  108. rolls.append(random.randint(1, type))
  109. return rolls
  110. def get_info(self, user):
  111. total_joins = queries.get_user_total_joins(self, user.id)
  112. total_kicks = queries.get_user_total_kicks(self, user.id)
  113. total_kicked = queries.get_user_total_kicked(self, user.id)
  114. total_messages = queries.get_user_total_messages(self, user.id)
  115. total_actions = queries.get_user_total_actions(self, user.id)
  116. total_notices = queries.get_user_total_notices(self, user.id)
  117. total_cursewords_added = queries.get_user_total_cursewords_added(self, user.id)
  118. total_curseadjectives_added = queries.get_user_total_curseadjectives_added(self, user.id)
  119. total_cursewords_banned = queries.get_user_total_cursewords_banned(self, user.id)
  120. total_curseadjectives_banned = queries.get_user_total_curseadjectives_banned(self, user.id)
  121. gamestats = queries.get_user_gamestats(self, user.id)
  122. xp_spent = gamestats[0]
  123. level = gamestats[1]
  124. coin = gamestats[2]
  125. coin_given = gamestats[3]
  126. coin_spent = gamestats[4]
  127. ap_spent = gamestats[5]
  128. karma_correction = gamestats[6]
  129. # Experience & action points.
  130. chat_xp = total_messages + (total_actions * 3) + (total_notices / 3)
  131. print('chat_xp:' + str(chat_xp) + ' = total_messages:' + str(total_messages) + ' + ( total_actions:' + str(total_actions) + ' *3) + ( + total_notices:' + str(total_notices) + ' / 3)')
  132. curse_add_xp = (total_cursewords_added + total_curseadjectives_added) * 10.1
  133. print('curse_add_xp:' + str(curse_add_xp) + ' = (total_cursewords_added:' + str(total_cursewords_added) + ' + total_curseadjectives_added:' + str(total_curseadjectives_added) + ') * 10.1')
  134. coin_xp = (coin_given * 5.1) + coin_spent
  135. print('coin_xp:' + str(coin_xp) + ' = (coin_given:' + str(coin_given) + ' * 5) + coin_spent:' + str(coin_spent))
  136. total_xp = (chat_xp + curse_add_xp + coin_xp + total_joins + total_kicks + total_kicked + ap_spent) / 10.1
  137. print('total_xp:' + str(total_xp) + ' = chat_xp:' + str(chat_xp) + ' + curse_add_xp: ' + str(curse_add_xp) + ' + coin_xp:' + str(coin_xp) + ' + total_joins:' + str(total_joins) + ' + total_kicks:' + str(total_kicks) + ' + total_kicked:' + str(total_kicked) + ' + ap_spent :' + str(ap_spent) + ' / 10.1')
  138. xp = (total_xp - xp_spent) - (level * 2.1)
  139. print('xp:' + str(xp) + ' = (total_xp:' + str(total_xp) + ' - xp_spent:' + str(xp_spent) + ') - (level:' + str(level) + ' * 2.1))')
  140. ap = (total_xp / 3.1) - ap_spent
  141. print('ap:' + str(ap) + ' = (total_xp:' + str(total_xp) + ' / 3.1) - ap_spent:' + str(ap_spent))
  142. # Karma.
  143. if total_xp == 0:
  144. total_xp = 0.01
  145. join_karma = total_joins / total_xp
  146. print('join_karma:' + str(join_karma) + ' = joins:' + str(total_joins) + ' / total_xp:' + str(total_xp))
  147. kick_karma = (total_kicks + total_kicked) / total_xp
  148. print('kick_karma:' + str(kick_karma) + ' = (given:' + str(total_kicks) + ' + received:' + str(total_kicked) + ') / total_xp:' + str(total_xp))
  149. shout_karma = total_notices / total_xp
  150. print('shout_karma:' + str(shout_karma) + ' = total_notices:' + str(total_notices) + ' + / total_xp:' + str(total_xp))
  151. curse_add_karma = ((total_cursewords_added + total_curseadjectives_added) * 10) / total_xp
  152. print('curse_add_karma:' + str(curse_add_karma) + ' = ((total_cursewords_added:' + str(total_cursewords_added) + ' + total_curseadjectives_added:' + str(total_curseadjectives_added) + ') * 10 ) / total_xp:'+ str(total_xp))
  153. curse_ban_karma = ((total_cursewords_banned + total_curseadjectives_banned) * 50) / total_xp
  154. print('curse_ban_karma:' + str(curse_ban_karma) + ' = ((total_cursewords_banned:' + str(total_cursewords_banned) + ' + total_curseadjectives_banned:' + str(total_curseadjectives_banned) + ') * 10 ) / total_xp:'+ str(total_xp))
  155. wealth_karma = (coin * 50.1) / total_xp
  156. print('wealth_karma:' + str(wealth_karma) + ' = (coin:' + str(coin) + ' * 50) / total_xp:' + str(total_xp))
  157. charity_karma = (coin_given * 10.1) / total_xp
  158. print('charity_karma:' + str(charity_karma) + ' = (coin_given:' + str(coin_given) + ' * 10) / total_xp:' + str(total_xp))
  159. elite_karma_bonus = 0
  160. i = 0
  161. for channel in self.channels:
  162. if userstatus.atleast_voiced(self, user.name, channel[i]):
  163. print(channel[i])
  164. elite_karma_bonus += 1
  165. print(elite_karma_bonus)
  166. i += 1
  167. karma = float(karma_correction) + float(charity_karma) + elite_karma_bonus + float(curse_add_karma) - float(curse_ban_karma) - float(join_karma) - float(kick_karma) - float(shout_karma) - float(wealth_karma)
  168. print('karma: ' + str(karma) + ' = karma_correction:' + str(karma_correction) + ' + charity_karma:' + str(charity_karma) + ' + elite_karma_bonus:' + str(elite_karma_bonus) + ' + curse_karma:' + str(curse_add_karma) + ' - curse_ban_karma:' + str(curse_ban_karma) + ' - join_karma:' + str(join_karma) + ' - kick_karma:' + str(kick_karma) + ' - shout_karma:' + str(shout_karma) + ' - wealth_karma:' + str(wealth_karma))
  169. return level, xp, xp_spent, total_xp, karma, coin, coin_spent, coin_given, ap, ap_spent
  170. def player_info(self, user):
  171. level, xp, xp_spent, total_xp, karma, coin, coin_spent, coin_given, ap, ap_spent = GameHelpers.get_info(self, user)
  172. #return 'Level: ' + str(level) + font.grey + ", " + font.reset + "XP: " + str(int(xp)) + "/" + font.grey + str(round(total_xp, 4)) + ", " + font.reset + "AP: " + str(int(ap)) + font.grey + ", " + font.reset + "coin: " + str(coin) + font.grey + "[S " + str(coin_spent) + ", G " + str(coin_given) + "], " + font.reset + "karma: " + str(round(karma, 4))
  173. return 'Level: ' + str(level) + font.grey + ", " + font.reset + "XP: " + str(int(xp)) + "/" + font.grey + str(int(total_xp)) + ", " + font.reset + "AP: " + str(int(ap)) + font.grey + ", " + font.reset + "coin: " + str(coin) + font.grey + "[S " + str(coin_spent) + ", G " + str(coin_given) + "], " + font.reset + "karma: " + str(round(karma, 4))
  174. def list_top_players(self, sort):
  175. result = queries.get_top_users(self, sort)
  176. if sort == "level":
  177. column = 2
  178. if sort == "xp_spent":
  179. column = 3
  180. if sort == "coin":
  181. column = 4
  182. message = ""
  183. for record in result:
  184. if not int(record[column]) < 1:
  185. level, xp, xp_spent, total_xp, karma, coin, coin_spent, coin_given, ap, ap_spent = GameHelpers.get_info(self, record)
  186. message += font.red + str(record[1]) + font.grey + " L " + font.green + str(level) + font.grey + ", XP " + font.green + str(int(xp)) + font.grey + "/" + str(int(total_xp)) + ", A " + font.green + str(int(ap)) + font.grey + ", C " + font.green + str(coin) + font.grey + ", K " + font.green + str(round(karma, 2)) + font.grey + ", "
  187. return message[:-2]