Guest User

Untitled

a guest
Mar 31st, 2019
522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.67 KB | None | 0 0
  1. '''
  2. Created by Preston J.
  3. Using discord.py on Python 3.6.7
  4. WingBot is a discord bot that listens for chat commands, and does something in return.
  5. '''
  6.  
  7. import time
  8. import datetime
  9. import discord
  10. import unicodedata
  11. from discord.ext import commands
  12. from discord.ext.commands import CommandNotFound
  13. import asyncio
  14.  
  15. if not discord.opus.is_loaded():
  16. discord.opus.load_opus('opus')
  17.  
  18. # WingBot Client Token so the program can communicate with the bot
  19. TOKEN = ''
  20.  
  21. client = commands.Bot(command_prefix = '.')
  22.  
  23. players = {} # This dictionary is used so the bot can be used in multiple servers.
  24.  
  25. def executed(cmd, user): # This function logs the commands that are executed, who they're executed by, and when they were executed.
  26. log_f = open('WingBotlog.txt', 'a')
  27. x = datetime.datetime.now()
  28. executed = '{} command executed by {} on {}-{}-{} at {}:{}:{}'.format(cmd, user, x.month, x.day, x.year, x.hour, x.minute, x.second)
  29. log_f.write('\n{} command executed by {} on {}-{}-{} at {}:{}:{}'.format(cmd, user, x.month, x.day, x.year, x.hour, x.minute, x.second))
  30. log_f.close()
  31. return executed
  32.  
  33. async def chatCommand(message, msg, file, file2, cmd): # This function makes the process of creating chat commands easier.
  34. if msg != None:
  35. await client.send_message(message.channel, msg)
  36. if file != None:
  37. await client.send_file(message.channel, file)
  38. if file2 != None:
  39. await client.send_file(message.channel, file2)
  40. if cmd != None:
  41. print(executed(cmd, message.author))
  42.  
  43. async def voiceCommand(ctx, message, file, time, cmd):
  44. channel = ctx.message.author.voice.voice_channel
  45. if channel == None: # If the user who sent the voice command isn't in a voice channel.
  46. await client.say('You are not in a voice channel, therefore I cannot run this command.')
  47. return
  48. else: # If the user is in a voice channel
  49. print(executed(cmd, message.author))
  50. voice = await client.join_voice_channel(channel)
  51. server = ctx.message.server
  52. voice_client = client.voice_client_in(server)
  53. player = voice.create_ffmpeg_player(file) # Uses ffmpeg to create a player, however it makes a pop up when it runs.
  54. player.start()
  55. time.sleep(float(time))
  56. await voice_client.disconnect() # Disconnects WingBot from the voice channel.
  57.  
  58.  
  59.  
  60. file = open('banlist.txt', 'r')
  61. banlist = []
  62. for line in file:
  63. line = line.strip() # This strips every \n in the textfile when porting the IDs to the list.
  64. banlist.append(str(line))
  65. print('Banlist: {}'.format(banlist))
  66.  
  67. @client.event
  68. # When the bot starts up, and is ready to be used on the Discord app, it will notify terminal.
  69. async def on_ready():
  70. print('WingBot Starting...')
  71. print('Ready for Use')
  72. botservers = []
  73. for server in client.servers:
  74. fixedserver = unicodedata.normalize('NFKD', str(server)).encode('ascii','ignore')
  75. botservers.append(fixedserver)
  76. print('Servers the bot is in: {}'.format(botservers))
  77. print('-------------------')
  78.  
  79. @client.event
  80. async def on_command_error(ctx, error): # This takes the useless CommandNotFound error, and prevents shell from printing it.
  81. if isinstance(error, CommandNotFound):
  82. return
  83.  
  84. @client.event
  85. async def on_message(message): # When WingBot detects that a message is sent.
  86.  
  87. if message.author == client.user: # If the message the bot detects is from the bot itself, it doesn't do anything.
  88. return
  89.  
  90. bruhcommands = ['.bruhhelp', '.bruh', '.saybruh', '.wing', '.duskiewing', '.cole', '.bigbruh',
  91. '.brucc', '.banfrombot', '.breh', '.tanner', '.kanye', '.verizonbald', '.traffic']
  92.  
  93. if message.author.id == '247199003844935680':
  94. await chatCommand(message, '<@247199003844935680> bot', None, None, None)
  95.  
  96. if message.author.id == '205855331178381313':
  97. await chatCommand(message, '<@205855331178381313> Bald', 'Male04.jpg', None, None)
  98.  
  99. if message.content in bruhcommands and message.author.id in banlist:
  100. await client.send_message(message.channel, 'You are banned from using the bot <@{}>!'.format(message.author.id))
  101. else:
  102. # Commands it listens to from the user:
  103.  
  104. if message.content == '.bruhhelp': # Using a msg variable because of the long text
  105. msg = 'Here is a website containing all of the WingBot Commands: https://sites.google.com/view/wingbotcommands/home'
  106. await chatCommand(message, msg, None, None, 'bruhhelp')
  107.  
  108. if message.content == '.bruh':
  109. await chatCommand(message, '{0.author.mention} is a big bruh.'.format(message), 'bruhmoji.png', None, 'bruh')
  110.  
  111. if message.content == '.wing':
  112. await chatCommand(message, None, 'thewing.jpg', 'wantwing.jpg', 'wing')
  113.  
  114. if message.content == '.duskiewing':
  115. await chatCommand(message, None, 'duskiewing.jpg', None, 'duskiewing')
  116.  
  117. if message.content == '.breh':
  118. file = 'tanbald.png'
  119. await client.send_file(message.channel, file)
  120. print(executed('breh', message.author))
  121.  
  122. if message.content == '.saybruh':
  123. print(executed('saybruh', message.author))
  124.  
  125. if message.content == '.kanye':
  126. print(executed('kanye', message.author))
  127.  
  128. if message.content == '.tanner':
  129. print(executed('tanner', message.author))
  130.  
  131. if message.content == '.baldverizon':
  132. print(executed('baldverizon', message.author))
  133.  
  134. if message.content == '.banfrombot' and message.author.id == '195341565089153026': # Capn's ID by default
  135. print(executed('banfrombot', message.author))
  136.  
  137. if message.content == '.traffic':
  138. print(executed('bigbruh', message.author))
  139.  
  140. if message.content == '.brucc':
  141. print(executed('brucc', message.author))
  142.  
  143. await client.process_commands(message) #This is used so that on_message events can be checked while commands are checked
  144.  
  145. @client.command(pass_context = True)
  146. async def bigbruh(ctx):
  147. voiceCommand(ctx, message, 'bigbruh.mp3', '0.5', 'bigbruh')
  148.  
  149. @client.command(pass_context = True)
  150. async def banfrombot(ctx, discid=None):
  151. global banlist
  152. adminid = '195341565089153026'
  153. if discid == None:
  154. await client.say('Missing required argument: Discord ID.')
  155. elif ctx.message.author.id == adminid:
  156. try:
  157. discid = int(discid)
  158. if str(discid) in banlist:
  159. await client.say('(ID {}) is already in the blacklist!'.format(discid))
  160. else:
  161. file = open('banlist.txt', 'a')
  162. file.write('\n{}'.format(discid))
  163. file.close()
  164. banlist.append(str(discid))
  165. await client.say('Added <@{}> to the blacklist.'.format(discid))
  166. except ValueError:
  167. await client.say('Must be a valid ID!')
  168. else:
  169. await client.say('You do not have permission to use this command!')
  170.  
  171. @client.command(pass_context = True)
  172. async def brucc(ctx):
  173. channel = ctx.message.author.voice.voice_channel
  174. if channel == None: # If the user who sent the .brucc command isn't in a voice channel.
  175. await client.say('You are not in a voice channel, therefore I cannot run this command.')
  176. return
  177. else: # If the user is in a voice channel
  178. voice = await client.join_voice_channel(channel)
  179. server = ctx.message.server
  180. voice_client = client.voice_client_in(server)
  181. player = voice.create_ffmpeg_player('brucc.mp3')
  182. player.start()
  183. time.sleep(25)
  184. await voice_client.disconnect() # Disconnects WingBot from the voice channel.
  185.  
  186. @client.command(pass_context = True)
  187. async def cole(ctx):
  188. channel = ctx.message.author.voice.voice_channel
  189. if channel == None: # If the user who sent the .cole command isn't in a voice channel.
  190. await client.say('You are not in a voice channel, therefore I cannot run this command.')
  191. return
  192. else: # If the user is in a voice channel
  193. voice = await client.join_voice_channel(channel)
  194. server = ctx.message.server
  195. voice_client = client.voice_client_in(server)
  196. player = voice.create_ffmpeg_player('cole.mp3')
  197. player.start()
  198. time.sleep(5)
  199. await voice_client.disconnect() # Disconnects WingBot from the voice channel.
  200.  
  201. @client.command(pass_context = True)
  202. async def tanner(ctx):
  203. channel = ctx.message.author.voice.voice_channel
  204. if channel == None: # If the user who sent the .tanner command isn't in a voice channel.
  205. await client.say('You are not in a voice channel, therefore I cannot run this command.')
  206. return
  207. else: # If the user is in a voice channel
  208. voice = await client.join_voice_channel(channel)
  209. server = ctx.message.server
  210. voice_client = client.voice_client_in(server)
  211. player = voice.create_ffmpeg_player('tanner.wav')
  212. player.start()
  213. time.sleep(16)
  214. await voice_client.disconnect() # Disconnects WingBot from the voice channel.
  215.  
  216. @client.command(pass_context = True)
  217. async def breh(ctx):
  218. channel = ctx.message.author.voice.voice_channel
  219. if channel == None: # If the user who sent the .breh command isn't in a voice channel.
  220. await client.say('You are not in a voice channel, therefore I cannot run this command.')
  221. return
  222. else: # If the user is in a voice channel
  223. voice = await client.join_voice_channel(channel)
  224. server = ctx.message.server
  225. voice_client = client.voice_client_in(server)
  226. player = voice.create_ffmpeg_player('Breh.wav')
  227. player.start()
  228. time.sleep(0.5)
  229. await voice_client.disconnect() # Disconnects WingBot from the voice channel.
  230.  
  231. @client.command(pass_context = True)
  232. async def baldverizon(ctx):
  233. channel = ctx.message.author.voice.voice_channel
  234. if channel == None: # If the user who sent the .baldverizon command isn't in a voice channel.
  235. await client.say('You are not in a voice channel, therefore I cannot run this command.')
  236. return
  237. else: # If the user is in a voice channel
  238. voice = await client.join_voice_channel(channel)
  239. server = ctx.message.server
  240. voice_client = client.voice_client_in(server)
  241. player = voice.create_ffmpeg_player('verizon.mp3')
  242. player.start()
  243. time.sleep(30)
  244. await voice_client.disconnect() # Disconnects WingBot from the voice channel.
  245.  
  246. @client.command(pass_context = True)
  247. async def kanye(ctx):
  248. channel = ctx.message.author.voice.voice_channel
  249. if channel == None: # If the user who sent the .kanye command isn't in a voice channel.
  250. await client.say('You are not in a voice channel, therefore I cannot run this command.')
  251. return
  252. else: # If the user is in a voice channel
  253. voice = await client.join_voice_channel(channel)
  254. server = ctx.message.server
  255. voice_client = client.voice_client_in(server)
  256. player = voice.create_ffmpeg_player('kanye.mp3')
  257. player.start()
  258. time.sleep(3)
  259. await voice_client.disconnect() # Disconnects WingBot from the voice channel.
  260.  
  261. @client.command(pass_context = True)
  262. async def saybruh(ctx):
  263. channel = ctx.message.author.voice.voice_channel
  264. if channel == None: # If the user who sent the .saybruh command isn't in a voice channel.
  265. await client.say('You are not in a voice channel, therefore I cannot run this command.')
  266. return
  267. else: # If the user is in a voice channel
  268. voice = await client.join_voice_channel(channel)
  269. server = ctx.message.server
  270. voice_client = client.voice_client_in(server)
  271. player = voice.create_ffmpeg_player('bruh.mp3')
  272. player.start()
  273. time.sleep(1)
  274. await voice_client.disconnect() # Disconnects WingBot from the voice channel.
  275.  
  276. @client.command(pass_context = True)
  277. async def traffic(ctx):
  278. channel = ctx.message.author.voice.voice_channel
  279. if channel == None: # If the user who sent the .traffic command isn't in a voice channel.
  280. await client.say('You are not in a voice channel, therefore I cannot run this command.')
  281. return
  282. else: # If the user is in a voice channel
  283. voice = await client.join_voice_channel(channel)
  284. server = ctx.message.server
  285. voice_client = client.voice_client_in(server)
  286. player = voice.create_ffmpeg_player('traffic.mp3')
  287. player.start()
  288. time.sleep(7.5)
  289. await voice_client.disconnect() # Disconnects WingBot from the voice channel.
  290.  
  291. # Starts communication to Discord and runs WingBot
  292. client.run(TOKEN)
Advertisement
Add Comment
Please, Sign In to add comment