common.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. show = False
  33. if rights["homechan"] == "owner":
  34. if self.channels[self.homechannel].is_owner(event.source.nick):
  35. show = True
  36. if rights["homechan"] == "admin":
  37. if self.channels[self.homechannel].is_owner(event.source.nick) or self.channels[self.homechannel].is_admin(event.source.nick):
  38. show = True
  39. if rights["homechan"] == "oper":
  40. 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):
  41. show = True
  42. if rights["chan"] == "owner":
  43. if self.channels[event.target].is_owner(event.source.nick):
  44. show = True
  45. if rights["chan"] == "admin":
  46. if self.channels[event.target].is_owner(event.source.nick) or self.channels[event.target].is_admin(event.source.nick):
  47. show = True
  48. if rights["chan"] == "oper":
  49. 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):
  50. show = True
  51. if show:
  52. return blue + self.cmdchar + command + reset + ", "
  53. else:
  54. return blue + self.cmdchar + command + reset + ", "
  55. def get_channelfunctions(self, channel):
  56. channelfunctions = self.db.one("SELECT join_greeting, statistics_commands, games FROM channels WHERE name='" + channel + "' AND network='" + self.network + "'")
  57. if channelfunctions[0]:
  58. joingreet = "on"
  59. else:
  60. joingreet = "off"
  61. if channelfunctions[1]:
  62. statscmds = "on"
  63. else:
  64. statscmds = "off"
  65. if channelfunctions[2]:
  66. games = "on"
  67. else:
  68. games = "off"
  69. return ("join_greeting " + joingreet + ", statistics_commands " + statscmds + ", games " + games + ".")
  70. def is_channelfunction(self, value):
  71. if value not in ["join_greeting", "statistics_commands", "games"]:
  72. return False
  73. else:
  74. return True
  75. class GameHelpers():
  76. def roll_dice(amount, type):
  77. rolls = []
  78. for iterations in range(amount):
  79. rolls.append(random.randint(1, type))
  80. return rolls