common.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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_curseword_added(self, user.id)
  118. total_curseadjectives_added = queries.get_user_total_curseadjective_added(self, user.id)
  119. gamestats = queries.get_user_gamestats(self, user.id)
  120. xp_spent = gamestats[0]
  121. level = gamestats[1]
  122. coin = gamestats[2]
  123. coin_given = gamestats[3]
  124. coin_spent = gamestats[4]
  125. ap_spent = gamestats[5]
  126. karma_correction = gamestats[6]
  127. # Experience & action points.
  128. chat_xp = total_messages + (total_actions * 3) + (total_notices / 3)
  129. print('chat_xp:' + str(chat_xp) + ' = total_messages:' + str(total_messages) + ' + ( total_actions:' + str(total_actions) + ' *3) + ( + total_notices:' + str(total_notices) + ' / 3)')
  130. curse_add_xp = (total_cursewords_added + total_curseadjectives_added) * 10.1
  131. print('curse_add_xp:' + str(curse_add_xp) + ' = (total_cursewords_added:' + str(total_cursewords_added) + ' + total_curseadjectives_added:' + str(total_curseadjectives_added) + ') * 10.1')
  132. coin_xp = (coin_given * 5.1) + coin_spent
  133. print('coin_xp:' + str(coin_xp) + ' = (coin_given:' + str(coin_given) + ' * 5) + coin_spent:' + str(coin_spent))
  134. total_xp = (chat_xp + curse_add_xp + coin_xp + total_joins + total_kicks + total_kicked + ap_spent) / 10.1
  135. 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')
  136. xp = (total_xp - xp_spent) - (level * 2.1)
  137. print('xp:' + str(xp) + ' = (total_xp:' + str(total_xp) + ' - xp_spent:' + str(xp_spent) + ') - (level:' + str(level) + ' * 2.1))')
  138. ap = (total_xp / 3.1) - ap_spent
  139. print('ap:' + str(ap) + ' = (total_xp:' + str(total_xp) + ' / 3.1) - ap_spent:' + str(ap_spent))
  140. # Karma.
  141. if total_xp == 0:
  142. total_xp = 0.01
  143. join_karma = total_joins / total_xp # High value should have negative impact.
  144. print('join_karma:' + str(join_karma) + ' = joins:' + str(total_joins) + ' / total_xp:' + str(total_xp))
  145. kick_karma = (total_kicks + total_kicked) / total_xp # High value should have negative impact.
  146. print('kick_karma:' + str(kick_karma) + ' = (given:' + str(total_kicks) + ' + received:' + str(total_kicked) + ') / total_xp:' + str(total_xp))
  147. shout_karma = total_notices / total_xp # High value should have negative impact.
  148. print('shout_karma:' + str(shout_karma) + ' = total_notices:' + str(total_notices) + ' + / total_xp:' + str(total_xp))
  149. curse_add_karma = ((total_cursewords_added + total_curseadjectives_added) * 10 ) / total_xp # High value should have positive impact.
  150. 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))
  151. wealth_karma = (coin * 50.1) / total_xp
  152. print('wealth_karma:' + str(wealth_karma) + ' = (coin:' + str(coin) + ' * 50) / total_xp:' + str(total_xp))
  153. charity_karma = (coin_given * 10.1) / total_xp
  154. print('charity_karma:' + str(charity_karma) + ' = (coin_given:' + str(coin_given) + ' * 10) / total_xp:' + str(total_xp))
  155. elite_karma_bonus = 0
  156. i = 0
  157. for channel in self.channels:
  158. if userstatus.atleast_voiced(self, user.name, channel[i]):
  159. print(channel[i])
  160. elite_karma_bonus += 1
  161. print(elite_karma_bonus)
  162. i += 1
  163. karma = float(karma_correction) + float(curse_add_karma) + float(charity_karma) + elite_karma_bonus - float(join_karma) - float(kick_karma) - float(shout_karma) - float(wealth_karma)
  164. print('karma: ' + str(karma) + ' = float(karma_correction:' + str(karma_correction) + ') + float(curse_karma:' + str(curse_add_karma) + ') + float(charity_karma:' + str(charity_karma) + ') + elite_karma_bonus:' + str(elite_karma_bonus) + ' - float(join_karma:' + str(join_karma) + ') - float(kick_karma:' + str(kick_karma) + ') - float(shout_karma:' + str(shout_karma) + ') - float(wealth_karma:' + str(wealth_karma) + ')')
  165. return level, xp, xp_spent, total_xp, karma, coin, coin_spent, coin_given, ap, ap_spent
  166. def player_info(self, user):
  167. level, xp, xp_spent, total_xp, karma, coin, coin_spent, coin_given, ap, ap_spent = GameHelpers.get_info(self, user)
  168. #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))
  169. 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))
  170. def list_top_players(self, sort):
  171. result = queries.get_top_users(self, sort)
  172. if sort == "level":
  173. column = 2
  174. if sort == "xp_spent":
  175. column = 3
  176. if sort == "coin":
  177. column = 4
  178. message = ""
  179. for record in result:
  180. if not int(record[column]) < 1:
  181. level, xp, xp_spent, total_xp, karma, coin, coin_spent, coin_given, ap, ap_spent = GameHelpers.get_info(self, record)
  182. 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 + ", "
  183. return message[:-2]