public.py 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. from common import userstatus, queries, font
  2. from commands.common import CommandHelpers as CH
  3. def do_command(self, connection, event, user, channel):
  4. cmdtype, trigger, command, replyto = CH.disect_command(self, event)
  5. # Do nothing if it's not a type of command.
  6. if not cmdtype:
  7. return
  8. # Do nothing if there is no command.
  9. if not command:
  10. return
  11. # The first word of the command sting with arguments, is just the command without arguments.
  12. try:
  13. one = command.split()[0]
  14. except:
  15. return
  16. # The actual commands:
  17. # if command == "test":
  18. # if cmdtype == "help": #Display help text.
  19. # if len(command.split()) != 1:
  20. # return
  21. # connection.privmsg(replyto, "Strictly for testing purposes only!")
  22. # elif cmdtype == "cmd":
  23. # connection.privmsg(replyto, str(self.channels[self.homechannel].owners()))
  24. # connection.privmsg(event.source.nick, self.channels[event.target].users())
  25. # Command list.
  26. if command == 'cmd' or command == 'cmds' or command == 'commands':
  27. if len(command.split()) == 1: # No arguments.
  28. if cmdtype == 'help': #Display help text.
  29. connection.privmsg(replyto, 'Displays a list of commands, usage: %s%s%s' % (font.blue, self.network.command_character, command))
  30. return
  31. elif cmdtype == 'cmd':
  32. connection.privmsg(replyto, '%sPublic: %s%s' % (font.grey, CH.ccc(self, "cmd"), CH.ccc(self, "help")[:-2]))# + CH.ccc(self, "away") + CH.ccc(self, "stopgreet")[:-2] + ".")
  33. if command == 'help':
  34. if cmdtype == 'help': #Display help text.
  35. if len(command.split()) != 1:
  36. return
  37. connection.privmsg(replyto, 'Explains how to get help on any specific command and hints the user to the commandlist. Example: %s%s%s' % (font.blue, self.network.command_character, command))
  38. elif cmdtype == 'cmd':
  39. connection.privmsg(replyto, "Replace the " + font.italic + self.network.command_character + " " + font.reset + "prefix of any comand with " + font.italic + self.network.help_character + " " + font.reset + "for help with a specific command. Request the command list with: " + font.blue + self.network.command_character + "cmd")
  40. connection.privmsg(replyto, font.grey + "Example: " + font.reset + font.blue + self.network.help_character + "help")
  41. # elif one == "stopgreet":
  42. # if cmdtype == "help": #Display help text.
  43. # if len(command.split()) != 1:
  44. # return
  45. # connection.privmsg(replyto, "Stops the bot from greeting you or a specific user. Channel, user and option to resume optional.")
  46. # connection.privmsg(replyto, font.grey + "Usage: " + font.blue + "!stopgreet " + font.reset + font.italic + "resume " + font.red + "channel user")
  47. # elif cmdtype == "cmd":
  48. #
  49. # # Check for resume variation of command.
  50. # resume = False
  51. # try:
  52. # if command.split()[1] == "resume":
  53. # resume = True
  54. # command = command.split(' ', 1)[1] # Remove the resume argument. Which makes the following logic easier.
  55. # except:
  56. # pass
  57. #
  58. # if len(command.split()) == 1: # No arguments.
  59. # if event.target == connection.get_nickname(): # PM.
  60. # connection.privmsg(replyto, "Specify at least a channel. For help type " + font.blue + self.network.help_character + "stopgreet" + font.reset + ".")
  61. # return
  62. # user = event.source.nick
  63. # channel = event.target
  64. #
  65. # if len(command.split()) == 2: # One argument.
  66. # if command.split()[1] not in self.channels: # Argument is not a channel the bot inhabits.
  67. # if event.target == connection.get_nickname(): # PM.
  68. # connection.action(replyto, "does not inhabit " + font.red + command.split()[1] + font.reset + ".")
  69. # return
  70. # # Channel message
  71. # if not userstatus.atleast_halfop(self, event.source.nick, self.homechannel) and not userstatus.atleast_halfop(self, event.source.nick, event.target): # Insufficient rights.
  72. # connection.privmsg(replyto, "Denied. You need to have at least halfop status in " + font.red + self.homechannel + font.reset + " or " + font.red + event.target + font.reset + ".")
  73. # return
  74. # # Stopgreet for x user in current channel
  75. # user = command.split()[1]
  76. # channel = event.target
  77. # else: # Bot inhabit channel.
  78. # user = event.source.nick
  79. # channel = command.split()[1]
  80. # if len(command.split()) == 3: # Two arguments.
  81. # if command.split()[1] not in self.channels: # Bot does not inhabit channel.
  82. # connection.action(replyto, "does not inhabit " + font.red + command.split()[1] + font.reset + ".")
  83. # return
  84. # if not userstatus.atleast_halfop(self, event.source.nick, self.homechannel) and not userstatus.atleast_halfop(self, event.source.nick, command.split()[1]): # Insufficient rights.
  85. # connection.privmsg(replyto, "Denied. You need to have at least halfop status in " + font.red + self.homechannel + font.reset + " or " + font.red + command.split()[1] + font.reset + ".")
  86. # return
  87. # user = command.split()[2]
  88. # channel = command.split()[1]
  89. # if len(command.split()) > 3: # Too many arguments.
  90. # connection.privmsg(replyto, "Too many arguments. For help type " + font.blue + self.network.help_character + "stopgreet" + font.reset + ".")
  91. # return
  92. #
  93. # # Check for database record.
  94. # result = self.db.one("SELECT id, stopgreet FROM joins WHERE LOWER(\"user\")=LOWER('" + user + "') AND user_network='" + self.network + "' AND LOWER(channel)=LOWER('" + channel + "') AND channel_network='" + self.network + "'")
  95. # if not result: # No record in database.
  96. # connection.action(replyto, "has not yet had the pleasure of greeting " + font.red + user + font.reset + " in " + font.red + channel + font.reset + ".")
  97. # return
  98. #
  99. # if resume:
  100. # stopgreet = False
  101. # message = "has already every intention to greet "
  102. # else:
  103. # stopgreet = True
  104. # message = "has already stopped greeting "
  105. # if result[1] == stopgreet:
  106. # connection.action(replyto, message + font.red + user + font.reset + " in " + font.red + channel + font.reset + ".")
  107. # return
  108. # print(str(stopgreet) + str(user) + str(channel))
  109. # try:
  110. # self.db.run("UPDATE joins SET stopgreet='" + str(stopgreet) + "' WHERE LOWER(\"user\")=LOWER('" + user + "') AND user_network='" + self.network + "' AND lower(channel)=LOWER('" + channel + "') AND channel_network='" + self.network + "'")
  111. # except:
  112. # connection.privmsg(replyto, "Failed to update database.")
  113. #
  114. # elif one == "away":
  115. # if cmdtype == "help": #Display help text.
  116. # if len(command.split()) != 1:
  117. # return
  118. # connection.privmsg(replyto, "Sets you away, optionally with reason. This affects the !seen command and the game.")
  119. # connection.privmsg(replyto, font.grey + "Usage: " + font.blue + "!away " + font.reset + font.italic + "reason")
  120. #
  121. # elif cmdtype == "cmd":
  122. # queries.create_ifnot_onrecord(self, "users", event.source.nick)
  123. # if len(trigger.split()) == 1:
  124. # self.db.run("UPDATE users SET away=TRUE, away_reason=NULL WHERE name='" + event.source.nick + "' AND network='" + self.network + "'")
  125. # else:
  126. # self.db.run("UPDATE users SET away=TRUE, away_reason=%s WHERE name='" + event.source.nick + "' AND network='" + self.network + "'", (trigger.split(maxsplit=1)[1], ))