You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

366 lines
11KB

  1. # RoxBot
  2. # Version = 0.1
  3. # Author = Roxxers
  4. ##############
  5. # To-do List #
  6. ##############
  7. # TODO: On member role assign, welcome member using on_member_update
  8. # TODO: Better help menu- AutoGen using <command>.help
  9. # TODO: WaifuRater - Mention user and RNG a rating
  10. # TODO: Admin tools - For commands already in and things like purge a chat
  11. # TODO: Overwatch stats - Using Overwatch-API lib
  12. import json
  13. import random
  14. import discord
  15. from discord.ext.commands import Bot
  16. bot = Bot(command_prefix=".")
  17. #bot.remove_command("help")
  18. token = ''
  19. token_roxbot = ""
  20. owner_id = "142735312626515979"
  21. config_template = {
  22. "example": {
  23. "greets": {
  24. "enabled": 0,
  25. "welcome-channel": "",
  26. "member-role": ""
  27. },
  28. "goodbyes": {
  29. "enabled": 0,
  30. "goodbye-channel": ""
  31. },
  32. "self-assign_roles": {
  33. "enabled": 0,
  34. "roles": []
  35. }
  36. }
  37. }
  38. def owner(ctx):
  39. if owner_id == ctx.author.id:
  40. return True
  41. else:
  42. return False
  43. def updateconfig():
  44. with open('config.json', 'w') as conf_file:
  45. json.dump(config, conf_file)
  46. def mention_commandee(ctx):
  47. return ctx.message.author
  48. def blacklisted(user):
  49. with open("blacklist.txt", "r") as fp:
  50. for line in fp.readlines():
  51. if user.id+"\n" == line:
  52. return True
  53. return False
  54. def dice_roll(num):
  55. if num == 100:
  56. step = 10
  57. else:
  58. step = 1
  59. return random.randrange(step, num+1, step)
  60. @bot.event
  61. async def on_ready():
  62. print("Client logged in\n\n")
  63. print("Servers I am currently in:\n")
  64. for server in bot.servers:
  65. print(server)
  66. @bot.event
  67. async def on_member_update(before, after):
  68. if True:
  69. return
  70. for role in before.roles:
  71. print(role.name)
  72. for role in after.roles:
  73. print(role.name)
  74. @bot.event
  75. async def on_message(message):
  76. if blacklisted(message.author):
  77. return
  78. else:
  79. return await bot.process_commands(message)
  80. @bot.event
  81. async def on_member_join(member):
  82. """
  83. Greets users when they join a server.
  84. :param member:
  85. :return:
  86. """
  87. if not config[member.server.id]["greets"]["enabled"]:
  88. return
  89. em = discord.Embed(
  90. title="Welcome to {}!".format(member.server),
  91. description='Hey {}! Welcome to {}! Be sure to read the rules.'.format(member.mention, member.server),
  92. colour=0xDEADBF)
  93. if config[member.server.id]["greets"]["welcome-channel"]:
  94. channel = discord.Object(config[member.server.id]["greets"]["welcome-channel"])
  95. else:
  96. channel = member.server.default_channel
  97. return await bot.send_message(channel,embed=em)
  98. @bot.event
  99. async def on_member_remove(member):
  100. if not config[member.server.id]["goodbyes"]["enabled"]:
  101. return
  102. else:
  103. return await bot.send_message(member.server,embed=discord.Embed(
  104. description="{}#{} has left or been beaned.".format(member.name, member.discriminator), colour=0xDEADBF))
  105. @bot.event
  106. async def on_server_join(server):
  107. config[server.id] = config_template["example"]
  108. updateconfig()
  109. @bot.event
  110. async def on_server_remove(server):
  111. config.pop(server.id)
  112. updateconfig()
  113. @bot.command(pass_context=True)
  114. async def iam(ctx, role: discord.Role = None, *, user: discord.User = None, server: discord.Server = None):
  115. if not config[ctx.message.server.id]["self-assign_roles"]["enabled"]:
  116. return
  117. user = ctx.message.author
  118. server = ctx.message.server
  119. if role not in server.roles:
  120. return await bot.say("That role doesn't exist. Roles are case sensitive. ")
  121. if role in user.roles:
  122. return await bot.say("You already have that role.")
  123. if role.id in config[ctx.message.server.id]["self-assign_roles"]["roles"]:
  124. await bot.add_roles(user, role)
  125. print("{} added {} to themselves in {} on {}".format(user.display_name, role.name, ctx.message.channel,
  126. ctx.message.server))
  127. return await bot.say("Yay {}! You now have the {} role!".format(user.mention, role.name))
  128. else:
  129. return await bot.say("That role is not self-assignable.")
  130. """@bot.command(pass_context=True)
  131. async def help(ctx):
  132. return await bot.say("Not that")"""
  133. @bot.command(pass_context=True)
  134. async def blacklist(ctx, option, *mentions):
  135. """
  136. Usage:
  137. .blacklist [ + | - | add | remove ] @UserName [@UserName2 ...]
  138. Add or remove users to the blacklist.
  139. Blacklisted users are forbidden from using bot commands.
  140. Only the bot owner can use this command
  141. """
  142. if not owner(ctx):
  143. return await bot.reply("You do not have permission to do this command.", delete_after=20)
  144. blacklist_amount = 0
  145. mentions = ctx.message.mentions
  146. if not mentions:
  147. bot.say("You didn't mention anyone")
  148. if option not in ['+', '-', 'add', 'remove']:
  149. return await bot.say('Invalid option "%s" specified, use +, -, add, or remove' % option, expire_in=20)
  150. for user in mentions:
  151. if user.id == owner_id:
  152. print("[Commands:Blacklist] The owner cannot be blacklisted.")
  153. await bot.say("The owner cannot be blacklisted.")
  154. mentions.remove(user)
  155. if option in ['+', 'add']:
  156. with open("blacklist.txt", "r") as fp:
  157. for user in mentions:
  158. for line in fp.readlines():
  159. if user.id+"\n" in line:
  160. mentions.remove(user)
  161. with open("blacklist.txt","a+") as fp:
  162. lines = fp.readlines()
  163. for user in mentions:
  164. if user.id not in lines:
  165. fp.write("{}\n".format(user.id))
  166. blacklist_amount += 1
  167. return await bot.say('{} users have been added to the blacklist'.format(blacklist_amount))
  168. else:
  169. with open("blacklist.txt","r") as fp:
  170. lines = fp.readlines()
  171. with open("blacklist.txt","w") as fp:
  172. for user in mentions:
  173. for line in lines:
  174. if user.id+"\n" != line:
  175. fp.write(line)
  176. else:
  177. fp.write("")
  178. blacklist_amount += 1
  179. return await bot.say('{} users have been removed from the blacklist'.format(blacklist_amount))
  180. @bot.command(pass_context=True, enabled=False)
  181. async def dice(ctx, num, *, user: discord.User = None):
  182. # TODO: Change to ndx format
  183. die = ("4","6","8","10","12","20","100")
  184. if num not in die:
  185. if num == "help":
  186. return await bot.say("!dice - This command random roles a dice. The die I support are (4, 6, 8, 10, 12, 20, 100) like the ones used in Table Top games.")
  187. else:
  188. return await bot.say("That is not a dice I know. Try !dice help for help!")
  189. user = mention_commandee(ctx)
  190. roll = dice_roll(int(num))
  191. return await bot.say("You rolled a {}, {}".format(roll,user.mention))
  192. """"@bot.command(pass_context=True)
  193. async def cat(self,ctx):
  194. from PIL import Image
  195. images = [None] * 3
  196. images[0] = Image.open("1.png")
  197. images[1] = Image.open("2.png")
  198. images[2] = Image.open("3.png")
  199. do = 3
  200. widths, heights = zip(*(i.size for i in images))
  201. total_width = sum(widths)
  202. max_height = max(heights)
  203. new_im = Image.new('RGBA', (total_width, max_height))
  204. x_offset = 0
  205. for im in images:
  206. new_im.paste(im, (x_offset, 0))
  207. x_offset += im.size[0]
  208. new_im.save('test.png')
  209. with Image.open("test.png") as fp:
  210. await self.bot.send_file(ctx.message.channel,"test.png")
  211. """
  212. @bot.command(pass_context=True)
  213. async def suck(ctx, user: discord.User = None):
  214. if user is None:
  215. try:
  216. user = ctx.message.mentions[0]
  217. except:
  218. return await bot.say("You didn't mention someone for me to suck")
  219. return await bot.say(":eggplant: :sweat_drops: :tongue: {}".format(user.mention))
  220. @bot.command(enabled=False)
  221. async def printcommands():
  222. for command in bot.commands:
  223. print(command)
  224. return await bot.say("Done.")
  225. @bot.command(pass_context=True)
  226. async def listroles(ctx):
  227. roles = []
  228. for role in config[ctx.message.server.id]["self-assign_roles"]["roles"]:
  229. for serverrole in ctx.message.server.roles:
  230. if role == serverrole.id:
  231. roles.append(serverrole.name)
  232. return await bot.say(roles)
  233. #################
  234. # Owner Commands#
  235. #################
  236. @bot.command(pass_context=True)
  237. async def addrole(ctx, role: discord.Role = None):
  238. # Add Remove List Help
  239. if not owner:
  240. return
  241. else:
  242. config[ctx.message.server.id]["self-assign_roles"]["roles"].append(role.id)
  243. updateconfig()
  244. return await bot.say('Role "{}" added'.format(str(role)))
  245. @bot.command(pass_context=True)
  246. async def removerole(ctx, role: discord.Role = None):
  247. if not owner:
  248. return
  249. count = 0
  250. for sa_role in config[ctx.message.server.id]["self-assign_roles"]["roles"]:
  251. if sa_role == role.id:
  252. config[ctx.message.server.id]["self-assign_roles"]["roles"].pop(count)
  253. updateconfig()
  254. return await bot.say('"{}" has been removed from the self-assignable roles.'.format(str(role)))
  255. else:
  256. count += 1
  257. return await bot.say("That role was not in the list.")
  258. @bot.command(pass_context=True)
  259. async def enablemodule(ctx, module):
  260. if not owner:
  261. return await bot.say("You ain't the owner, normie get out!!! REEE!")
  262. else:
  263. if module in config[ctx.message.server.id]:
  264. if not config[ctx.message.server.id][module]["enabled"]:
  265. config[ctx.message.server.id][module]["enabled"] = 1
  266. updateconfig()
  267. return await bot.say("'{}' was enabled!".format(module))
  268. else:
  269. config[ctx.message.server.id][module]["enabled"] = 0
  270. updateconfig()
  271. return await bot.say("'{}' was disabled :cry:".format(module))
  272. else:
  273. return await bot.say("That module dont exist fam. You made the thing")
  274. @bot.command(pass_context=True)
  275. async def welcomechannel(ctx, channel: discord.Channel = None):
  276. config[ctx.message.server.id]["greets"]["welcome-channel"] = channel.id
  277. updateconfig()
  278. return await bot.say("{} has been set as the welcome channel!".format(channel.mention))
  279. @bot.command(pass_context=True)
  280. async def goodbyechannel(ctx, channel: discord.Channel = None):
  281. config[ctx.message.server.id]["goodbyes"]["goodbye-channel"] = channel.id
  282. updateconfig()
  283. return await bot.say("{} has been set as the goodbye channel!".format(channel.mention))
  284. if __name__ == "__main__":
  285. with open('config.json', 'r') as config_file:
  286. config = json.load(config_file)
  287. bot.run(token)