Advertisement
Guest User

Untitled

a guest
Jan 10th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.13 KB | None | 0 0
  1. import discord
  2. import asyncio
  3. import random
  4. import time
  5. import praw
  6. from googletrans import Translator
  7. from weather import Weather
  8.  
  9. exp = 'exp.txt'
  10. #'/Users/Cy/Desktop/,/School/Personal Project/suzuakze/exp.txt'
  11. cache = 'cache.txt'
  12. #'/Users/Cy/Desktop/,/School/Personal Project/suzuakze/cache.txt'
  13. stalk_market = 'stalk_market.txt'
  14. #'/Users/Cy/Desktop/,/School/Personal Project/suzuakze/stalk_market.txt'
  15.  
  16. client = discord.Client()
  17. r = praw.Reddit(client_id = "pB1R1zx8nq-Obw", client_secret = "wgSaKS4HzUtHEXyBIusSRLrjI2M", user_agent = "/u/c2ke", username = "DoritoFaceBot", password = "thisisapassword")
  18. t = Translator()
  19. w = Weather()
  20.  
  21. stalk = 2000
  22. last_message = 0
  23. up = 30
  24. down = 40
  25. same = 50
  26.  
  27. @client.event
  28. async def on_message(message):
  29. global stalk
  30. global last_message
  31. global up
  32. global down
  33. global same
  34.  
  35. if message.author == client.user:
  36. return
  37.  
  38. #----------------------------------------------------------------------------------------
  39.  
  40. if message.content.lower().startswith("!hello"):
  41. msg = "hi {0.author.mention}!".format(message)
  42. await client.send_message(message.channel, msg)
  43. print('!hello, ' + str(message.author))
  44.  
  45. if message.content.lower().startswith('!help'):
  46. await client.send_message(message.channel, "i'm currently in my alpha stage. the primary commands i have right now are:")
  47. await client.send_message(message.channel, "`!hello`, `!dice`, `!flip`, `role`, `!exp`, `!stalk help`, `!translate`, `!weather`, `!wp`, `!showerthought`, and `!til`")
  48. await client.send_message(message.channel, 'read more about each command here: *insert evan\'s website here*')
  49. print('!help, ' + str(message.author))
  50.  
  51. if message.content.lower().startswith("ty suzukaze"):
  52. await client.send_message(message.channel, "i'm glad i could help!")
  53.  
  54. #add image based thingies
  55. #redo help
  56.  
  57. #----------------------------------------------------------------------------------------
  58.  
  59. if message.content.lower().startswith('!dice'):
  60. randomDice = random.randint(1,6)
  61. await client.send_message(message.channel, "*shakes dice*")
  62. await asyncio.sleep(2)
  63. if randomDice == 6:
  64. await client.send_message(message.channel, "whoa, you got a **6**!")
  65.  
  66. else:
  67. await client.send_message(message.channel, "you got a **" + str(randomDice) + "**!")
  68. print('!dice, ' + str(message.author))
  69.  
  70. if message.content.lower().startswith('!flip'):
  71. if random.randint(1, 50) == 50:
  72. await client.send_message(message.channel, "(ヘ・_・)ヘ ┳━┳")
  73. await asyncio.sleep(1)
  74. await client.send_message(message.channel, "(╯°□°)╯︵ ┻━┻")
  75.  
  76. else:
  77. await client.send_message(message.channel, "*insert coin in air noises here*")
  78. await asyncio.sleep(1)
  79. if random.randint(1,2) == 1:
  80. await client.send_message(message.channel, "heads!")
  81.  
  82. else:
  83. await client.send_message(message.channel, "tails!")
  84. print('!flip, ' + str(message.author))
  85.  
  86. #ADD CHOICES OPTION
  87.  
  88. #----------------------------------------------------------------------------------------
  89.  
  90. if message.content.lower().startswith('!role'):
  91. roleList = ["10-1", "10-2", "math extended", "math plus", "math", "french", "spanish", "spanish plus", "computer science", "music", "visual arts", "theatre", "film", "creative writing", "theatre tech", "photography", "sports leadership", "spicy"]
  92. enteredRole = message.content[6:].lower()
  93. role = discord.utils.get(message.server.roles, name=enteredRole)
  94. roles = [
  95. "376175453171613698"
  96. "376175469097254914"
  97. "367774687528353792"
  98. "367780169521299477"
  99. "367780299821678593"
  100. "367780190140760065"
  101. "367780203654807552"
  102. "367780221425811458"
  103. "367780418969141258"
  104. "367780451554820106"
  105. "367780467459751939"
  106. "367780497289641986"
  107. "367780528138616833"
  108. "367780552155070465"
  109. "367780585420095488"
  110. "367780679208927233"
  111. "367781743333474304"
  112. "389503593356460032"
  113. ]
  114.  
  115. if role is None or role.name not in roleList:
  116. await client.send_message(message.channel, "sorry, i think that role doesnt exist! here's a list of roles i know of:")
  117. await client.send_message(message.channel, roleList)
  118. return
  119.  
  120. elif role in message.author.roles:
  121. await client.remove_roles(message.author, role)
  122. await client.send_message(message.channel, "i removed the role from your account :P")
  123. return
  124.  
  125. else:
  126. await client.add_roles(message.author, role)
  127.  
  128. if message.content.startswith('!role spicy'):
  129. await client.send_message(message.channel, "(~˘▾˘)~ as my creator would say, stay spicy my brochacho ~(˘▾˘~)")
  130.  
  131. else:
  132. await client.send_message(message.channel, "i added the role to your account :D")
  133. print('!role, ' + str(message.author))
  134.  
  135. #make sure roles are up-to-date
  136.  
  137. #----------------------------------------------------------------------------------------
  138.  
  139. if message.content.lower().startswith(''):
  140. count_cache = 0
  141. count_exp = 0
  142. cache_r = open(cache, 'r')
  143. exp_r = open(exp, 'r')
  144. before = ""
  145. middle = ""
  146. after = ""
  147. for x in cache_r:
  148. count_cache += 1
  149. if x.startswith(str(message.author)):
  150. break
  151.  
  152. for x in exp_r:
  153. count_exp += 1
  154. if count_exp <= count_cache - 1:
  155. before += str(x)
  156.  
  157. elif count_exp == count_cache:
  158. middle += str(x)
  159.  
  160. elif count_exp >= count_cache:
  161. after += str(x)
  162.  
  163. middle = int(middle.strip()) + len(message.content)
  164. exp_w = open(exp, 'w')
  165. exp_w.write(str(before))
  166. exp_w.write(str(middle) + "\n")
  167. exp_w.write(str(after))
  168. exp_w.close()
  169.  
  170. if message.content.lower().startswith('!exp'):
  171. count_cache = 0
  172. count_exp = 0
  173. cache_r = open(cache, 'r')
  174. exp_r = open(exp, 'r')
  175. for x in cache_r:
  176. count_cache += 1
  177. if x.startswith(str(message.author)):
  178. break
  179.  
  180. for x in exp_r:
  181. count_exp += 1
  182. if count_exp == count_cache:
  183. msg = ("{0.author.mention} has " + x.strip() + "EXP!").format(message)
  184. await client.send_message(message.channel, msg)
  185.  
  186. #add rank/leaderboard
  187.  
  188. #----------------------------------------------------------------------------------------
  189.  
  190. if message.content.lower().startswith(''):
  191. if stalk < 5:
  192. stalk = 5
  193.  
  194. if stalk > 1 and stalk < 2000:
  195. up = 100
  196. down = 20
  197. same = -20
  198.  
  199. if stalk > 2000 and stalk < 5000:
  200. up = 30
  201. down = 40
  202. same = 5
  203.  
  204. if stalk > 5000 and stalk < 8500:
  205. up = 35
  206. down = 60
  207. same = 100
  208.  
  209. if stalk > 7500 and stalk < 15000:
  210. up = 75
  211. down = 35
  212. same = -20
  213.  
  214. if stalk > 15000 and stalk < 2500:
  215. up = 10
  216. down = 50
  217. same = 100
  218.  
  219. if stalk > 25000:
  220. up = 30
  221. down = 40
  222. same = -20
  223.  
  224. if len(message.content) == last_message:
  225. stalk += same
  226. last_message = len(message.content)
  227.  
  228. elif len(message.content) >= last_message:
  229. stalk += up
  230. last_message = len(message.content)
  231.  
  232. elif len(message.content) <= last_message:
  233. stalk -= down
  234. last_message = len(message.content)
  235.  
  236. if message.content.lower().startswith('!stalk help'):
  237. await client.send_message(message.channel, 'to view current stalk prices, use `!stalk price`. to trade stalks, use `!stalk buy x` and `!stalk sell x`, with x being the amount of stalks.')
  238.  
  239. if message.content.lower().startswith('!stalk price'):
  240. await client.send_message(message.channel, "currently, a stalk sells for " + str(stalk) + "¥. Check your account with `!stalk portfolio`")
  241. print('!stalk price, ' + str(message.author))
  242.  
  243. if message.content.lower().startswith('!stalk portfolio'):
  244. stalk_r = open(stalk_market, 'r')
  245. cache_r = open(cache, 'r')
  246. count_cache_s = 0
  247. count_stalk = 0
  248.  
  249. for x in cache_r:
  250. count_cache_s += 1
  251. if x.startswith(str(message.author)):
  252. break
  253.  
  254. for x in stalk_r:
  255. count_stalk += 1
  256. if count_cache_s == count_stalk:
  257. stalk_yen = x.find('STK') + 3
  258. user_stalk = str(x[:stalk_yen])
  259. user_yen = str(x[stalk_yen:])
  260.  
  261. msg = ("{0.author.mention} has `" + user_stalk + "` and `" + user_yen.strip() + "¥`").strip().format(message)
  262. await client.send_message(message.channel, msg)
  263. print('!stock portfolio, ' + str(message.author))
  264.  
  265. if message.content.lower().startswith('!stalk buy '):
  266. stalk_r = open(stalk_market, 'r')
  267. stalk_r_2 = open(stalk_market, 'r')
  268. cache_r = open(cache, 'r')
  269. count_cache_s = 0
  270. count_stalk = 0
  271. count_stalk_s = 0
  272. pre = ""
  273. post = ""
  274. for x in cache_r:
  275. count_cache_s += 1
  276. if x.startswith(str(message.author)):
  277. break
  278.  
  279. for x in stalk_r:
  280. count_stalk += 1
  281. if count_stalk == count_cache_s:
  282. cordinates = 'the cartel\'s location will bring you the key to space'
  283.  
  284. elif count_stalk < count_cache_s:
  285. pre += str(x)
  286.  
  287. elif count_stalk > count_cache_s:
  288. post += str(x)
  289.  
  290. for x in stalk_r_2:
  291. count_stalk_s += 1
  292. if count_cache_s == count_stalk_s:
  293. stalk_cut = x.find('STK')
  294. yen_cut = x.find('STK') + 4
  295. user_stalk = str(x[:stalk_cut])
  296. user_yen = str(x[yen_cut:])
  297. amount = message.content[10:]
  298. total_price = stalk * int(amount)
  299. if int(total_price) <= int(user_yen):
  300. new_stalk = int(user_stalk) + int(amount)
  301. new_yen = int(user_yen) - int(total_price)
  302.  
  303. mid = str(new_stalk) + " STK " + str(new_yen)
  304. stalk_w = open(stalk_market, 'w')
  305. stalk_w.write(str(pre))
  306. stalk_w.write(str(mid) + "\n")
  307. stalk_w.write(str(post))
  308. stalk_w.close()
  309. await client.send_message(message.channel, "your account has been updated!")
  310.  
  311. else:
  312. await client.send_message(message.channel, "sorry, you don't seem to have enough yen...!")
  313. print('!stalk buy, ' + str(message.author))
  314.  
  315. if message.content.lower().startswith('!stalk sell '):
  316. stalk_r = open(stalk_market, 'r')
  317. stalk_r_2 = open(stalk_market, 'r')
  318. cache_r = open(cache, 'r')
  319. count_cache_ss = 0
  320. count_stalk_s = 0
  321. count_stalk_ss = 0
  322. pre = ""
  323. post = ""
  324. for x in cache_r:
  325. count_cache_ss += 1
  326. if x.startswith(str(message.author)):
  327. break
  328.  
  329. for x in stalk_r:
  330. count_stalk_s += 1
  331. if count_stalk_s == count_cache_ss:
  332. cordinates = 'the cartel\'s location will bring you the key to space'
  333.  
  334. elif count_stalk_s < count_cache_ss:
  335. pre += str(x)
  336.  
  337. elif count_stalk_s > count_cache_ss:
  338. post += str(x)
  339.  
  340. for x in stalk_r_2:
  341. count_stalk_ss += 1
  342. if count_cache_ss == count_stalk_ss:
  343. stalk_cut = x.find('STK')
  344. yen_cut = x.find('STK') + 4
  345. user_stalk = str(x[:stalk_cut])
  346. user_yen = str(x[yen_cut:]).strip()
  347. amount = message.content[12:]
  348. total_price = stalk * int(amount)
  349. if int(amount) <= int(user_stalk):
  350. new_stalk = int(user_stalk) - int(amount)
  351. new_yen = int(user_yen) + int(total_price)
  352. mid = str(new_stalk) + " STK " + str(new_yen)
  353. stalk_w = open(stalk_market, 'w')
  354. stalk_w.write(str(pre))
  355. stalk_w.write(str(mid) + "\n")
  356. stalk_w.write(str(post))
  357. stalk_w.close()
  358. await client.send_message(message.channel, "your account has been updated!")
  359.  
  360. else:
  361. await client.send_message(message.channel, "sorry, you don't seem to have enough stalks...!")
  362. print('!stock sell, ' + str(message.author))
  363.  
  364. #----------------------------------------------------------------------------------------
  365.  
  366. if message.content.lower().startswith('!translate'):
  367. trans = message.content[10:]
  368. completed_trans = t.translate(trans).text
  369. await client.send_message(message.channel, trans + " ---> " + completed_trans)
  370. print('!translate, ' + str(message.author))
  371.  
  372. #----------------------------------------------------------------------------------------
  373.  
  374. if message.content.lower().startswith('!weather'):
  375. location = w.lookup_by_location('Vancouver Canada')
  376. forecasts = location.forecast()
  377. count = 0
  378. for forecast in forecasts:
  379. count += 1
  380.  
  381. if count == 1:
  382. weather_message = (((float(forecast.high()) + float(forecast.low()))/2) - 32) * (5/9)
  383. await client.send_message(message.channel, 'today there\'s **' + forecast.text().lower() + '** with an average temperature of **' + str(int(weather_message)) + 'C**!')
  384.  
  385. if count == 2:
  386. weather_message = (((float(forecast.high()) + float(forecast.low()))/2) - 32) * (5/9)
  387. await client.send_message(message.channel, 'tommorrow there\'ll be **' + forecast.text().lower() + '** with an average temperature of **' + str(int(weather_message)) + 'C**!')
  388.  
  389. if count == 3:
  390. break
  391. print('!weather, ' + str(message.author))
  392.  
  393. #sunrise/sunset
  394.  
  395. #----------------------------------------------------------------------------------------
  396.  
  397. if message.content.lower().startswith('!wp'):
  398. prompts = ['']
  399. for submission in r.subreddit("WritingPrompts").hot(limit=25):
  400. if str(submission.title).startswith('[WP]'):
  401. prompts.append(submission.title)
  402.  
  403. await client.send_message(message.channel, 'here\'s a writing prompt i found from reddit!')
  404. await client.send_message(message.channel, '"' + prompts[random.randint(1, 23)] + '"')
  405. print('!wp, ' + str(message.author))
  406.  
  407. if message.content.lower().startswith('!showerthought'):
  408. prompts = ['']
  409. for submission in r.subreddit("Showerthoughts").hot(limit=25):
  410. prompts.append(submission.title)
  411.  
  412. await client.send_message(message.channel, 'here\'s a shower thought i found from reddit!')
  413. await client.send_message(message.channel, '"' + prompts[random.randint(1, 24)] + '"')
  414. print('!showerthought, ' + str(message.author))
  415.  
  416. if message.content.lower().startswith('!til'):
  417. prompts = ['']
  418. for submission in r.subreddit("TodayILearned").hot(limit=25):
  419. prompts.append(submission.title)
  420.  
  421. await client.send_message(message.channel, 'here\'s a fact i found from reddit!')
  422. await client.send_message(message.channel, '"' + prompts[random.randint(1, 25)] + '"')
  423. print('!til, ' + str(message.author))
  424.  
  425. #----------------------------------------------------------------------------------------
  426.  
  427. if message.content.lower().startswith('!focus'):
  428. role = discord.utils.get(message.server.roles, name="focusing")
  429. await client.add_roles(message.author, role)
  430. print('!focus, ' + str(message.author))
  431.  
  432. if message.content.lower().startswith('!unlock'):
  433. role = discord.utils.get(message.server.roles, name="focusing")
  434. await client.remove_roles(message.author, role)
  435. print('!unlock, ' + str(message.author))
  436.  
  437. #----------------------------------------------------------------------------------------
  438.  
  439. @client.event
  440. async def on_member_join(member):
  441. msg = ('welcome to SH2020 {0.mention}!').format(message)
  442. await client.send_message(discord.Object(id='372242666672619522'), msg)
  443. exp_w = open(exp, 'a')
  444. exp_w.write('0' + '\n')
  445. exp_w.close()
  446.  
  447. cache_w = open(cache, 'a')
  448. cache_w.write(message.author + '\n')
  449. exp_w.close()
  450.  
  451. stalk_w = open(stalk_market, 'a')
  452. stalk_w.write('1 STK 5000')
  453. stalk_w.close()
  454.  
  455. @client.event
  456. async def on_member_remove(member):
  457. msg = ('bye {0.mention} ;-;').format(message)
  458. await client.send_message(discord.Object(id='372242666672619522'), msg)
  459.  
  460. #----------------------------------------------------------------------------------------
  461.  
  462. @client.event
  463. async def on_ready():
  464. print("logged in as: " + client.user.name)
  465. print("------")
  466. await client.send_message(discord.Object(id='389506544544382996'), 'i\'m on!')
  467.  
  468. client.run("MzU5NzgzNjY2MzkxNTgwNjg1.DMA78w.t_KUNsPMI9X67PW9G6pFxWXCd94")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement