common.py 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import random
  2. bold = "\x02"
  3. italic = "\x1D"
  4. underline = "\x1F"
  5. reverse = "\x16" # swap background and foreground colors ("reverse video")
  6. reset = "\x0F"
  7. blue = "\x0302"
  8. green = "\x0303"
  9. red = "\x0304"
  10. grey = "\x0314"
  11. class CommandHelpers():
  12. def disect_command(self, event):
  13. trigger = event.arguments[0]
  14. command = trigger[1:] #Command without prefix.
  15. # Determine command type.
  16. if trigger.startswith(self.cmdchar):
  17. cmdtype = "cmd"
  18. elif trigger.startswith(self.helpchar):
  19. cmdtype = "help"
  20. else:
  21. cmdtype = False
  22. # Determine where to reply to.
  23. if event.type == "pubmsg":
  24. replyto = event.target
  25. elif event.type == "privmsg":
  26. replyto = event.source.nick
  27. else:
  28. replyto = False
  29. return(cmdtype, trigger, command, replyto)
  30. def ccc(self, command, rights=False, event=False): # Commandlist colour coding and channel rights filter.
  31. if rights:
  32. if rights["homechan"] == "owner":
  33. if self.channels[self.homechannel].is_owner(event.source.nick):
  34. show = True
  35. if rights["homechan"] == "admin":
  36. if self.channels[self.homechannel].is_owner(event.source.nick) or self.channels[self.homechannel].is_admin(event.source.nick):
  37. show = True
  38. if rights["homechan"] == "oper":
  39. if self.channels[self.homechannel].is_owner(event.source.nick) or self.channels[self.homechannel].is_admin(event.source.nick) or self.channels[self.homechannel].is_oper(event.source.nick):
  40. show = True
  41. if rights["chan"] == "owner":
  42. if self.channels[event.target].is_owner(event.source.nick):
  43. show = True
  44. if rights["chan"] == "admin":
  45. if self.channels[event.target].is_owner(event.source.nick) or self.channels[event.target].is_admin(event.source.nick):
  46. show = True
  47. if rights["chan"] == "oper":
  48. 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):
  49. show = True
  50. if show:
  51. return blue + self.cmdchar + command + reset + ", "
  52. else:
  53. return blue + self.cmdchar + command + reset + ", "
  54. def get_channelfunctions(self, channel):
  55. channelfunctions = self.db.one("SELECT join_greeting, statistics_commands, games FROM channels WHERE name='" + channel + "' AND network='" + self.network + "'")
  56. if channelfunctions[0]:
  57. joingreet = "on"
  58. else:
  59. joingreet = "off"
  60. if channelfunctions[1]:
  61. statscmds = "on"
  62. else:
  63. statscmds = "off"
  64. if channelfunctions[2]:
  65. games = "on"
  66. else:
  67. games = "off"
  68. return ("join_greeting " + joingreet + ", statistics_commands " + statscmds + ", games " + games + ".")
  69. def is_channelfunction(self, value):
  70. if value not in ["join_greeting", "statistics_commands", "games"]:
  71. return False
  72. else:
  73. return True
  74. class GameHelpers():
  75. def roll_dice(amount, type):
  76. rolls = []
  77. for iterations in range(amount):
  78. rolls.append(random.randint(1, type))
  79. return rolls