common.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 autojoin, join_greeting, statistics_commands, games FROM channels WHERE name='" + channel + "' AND network='" + self.network + "'")
  57. if channelfunctions[0]:
  58. autojoin = "on"
  59. else:
  60. autojoin = "off"
  61. if channelfunctions[1]:
  62. joingreet = "on"
  63. else:
  64. joingreet = "off"
  65. if channelfunctions[2]:
  66. statscmds = "on"
  67. else:
  68. statscmds = "off"
  69. if channelfunctions[3]:
  70. games = "on"
  71. else:
  72. games = "off"
  73. return ("autojoin " + autojoin + ", join_greeting " + joingreet + ", statistics_commands " + statscmds + ", games " + games + ".")
  74. def is_channelfunction(self, value):
  75. if value not in ["autojoin", "join_greeting", "statistics_commands", "games"]:
  76. return False
  77. else:
  78. return True
  79. class GameHelpers():
  80. def roll_dice(amount, type):
  81. rolls = []
  82. for iterations in range(amount):
  83. rolls.append(random.randint(1, type))
  84. return rolls