Advertisement
Guest User

Code

a guest
Nov 18th, 2019
736
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.02 KB | None | 0 0
  1. import random
  2. import asyncio
  3. import discord
  4. import csv
  5. import re
  6.  
  7. from discord.ext.commands import Bot
  8. from discord import Game
  9. from operator import itemgetter
  10. from os import environ
  11.  
  12. # The command prefix & bot token (KEEP TOKEN SECRET)
  13. commandPrefix, TOKEN = "c!", environ["TOKEN"]
  14. helpCommand = '{0}help'.format(commandPrefix)
  15.  
  16. # Initialise the client
  17. client = Bot(command_prefix=commandPrefix)
  18. client.remove_command("help")
  19.  
  20. @client.command(name="help")
  21. async def Help(ctx):
  22. await ctx.send( """```help Shows this message.
  23. id
  24. AddUser Add <member> to doc
  25. DelUser Delete <member> from doc
  26. Award Award points
  27. Punish Take points
  28. Points Check points
  29. ResetPoints Reset all points
  30. NewReward Add new reward
  31. DelReward Delete a reward
  32. Rewards List all rewards
  33. Nominate Nominate a game
  34. Accept Accept a game suggestion
  35. Reject Reject a game suggestion
  36. Games List all games in the list
  37. ResetGames Delete all games in the lists
  38. Vote Vote for a game
  39. Top Show top games
  40. Redeem Redeem a reward
  41.  
  42. Type c!help command for more info on a command.
  43. You can also type c!help category for more info on a category.```""")
  44.  
  45. # Check if a member is in the database
  46. def userInList(member):
  47. with open("Points_List.txt", "r", newline="") as file:
  48. found = False
  49. for row in csv.reader(file):
  50. if row[1] == str(member):
  51. found = True
  52. return found
  53.  
  54. # Returns a user's ID
  55. @client.command()
  56. async def id(ctx, member : discord.Member = ''):
  57. try:
  58. await ctx.send("{0}'s ID is {1}.".format(member.display_name, member.id))
  59. except AttributeError:
  60. await ctx.send("You did not specify a user!")
  61.  
  62. # Add a user to the points list
  63. def initUser(member : discord.Member):
  64. if userInList(member.id) == False: # Add member to list with 0 points
  65. with open("Points_List.txt", "a", newline='') as file:
  66. row = [member.name, member.id, 0]
  67.  
  68. writer = csv.writer(file)
  69. writer.writerow(row)
  70. return True
  71. else:
  72. return False
  73.  
  74. # Deletes a user from the points lists
  75. def delUser(member=''):
  76. with open("Points_List.txt", "r", newline='') as file:
  77. data = list(csv.reader(file))
  78.  
  79. deleted = False
  80.  
  81. with open("Points_List.txt", "w", newline='') as file:
  82. writer = csv.writer(file)
  83. for row in data:
  84. if row[1] == str(member.id):
  85. deleted = True
  86. else:
  87. writer.writerow(row)
  88.  
  89. if deleted == False:
  90. return False
  91. else:
  92. return True
  93.  
  94. #Adds a game to the list or suggestion
  95. def addGame(game, userID, userName):
  96. if len(game) == 0:
  97. return "You can't add a game with no name."
  98.  
  99. found = False
  100.  
  101. with open("Games_List.txt", "r", newline="") as file:
  102. for row in csv.reader(file):
  103. if row[0].capitalize() == game.capitalize():
  104. found = True
  105.  
  106. if userID == 142485371987427328:
  107.  
  108. if found:
  109. return "'{0}' is already in the list".format(game)
  110.  
  111. with open("Games_List.txt", "a", newline="") as file:
  112. writer = csv.writer(file)
  113. row = [game, 0]
  114.  
  115. writer.writerow(row)
  116.  
  117. with open("Games_Pending.txt", "r") as file:
  118. data = list(csv.reader(file))
  119.  
  120. with open("Games_Pending.txt", "w", newline="") as file:
  121. writer = csv.writer(file)
  122.  
  123. for row in data:
  124. if row[0].capitalize() == game.capitalize():
  125. rowtowrite = row
  126. rowtowrite.append("Accepted")
  127. writer.writerow(rowtowrite)
  128. else:
  129. writer.writerow(row)
  130.  
  131. return "'{0}' has been added successfully.".format(game)
  132.  
  133. else:
  134. if not found:
  135. suggestions = 0
  136. with open("Games_Pending.txt", "r", newline="") as file:
  137. for row in csv.reader(file):
  138. if row[0].capitalize() == game.capitalize():
  139. return "'{0}' has already been suggested.".format(game)
  140.  
  141. if row[1] == userName:
  142. suggestions += 1
  143. if suggestions > 1:
  144. return "You only get two suggestions per wave."
  145.  
  146. else:
  147. return "'{0}' is already in the list".format(game)
  148.  
  149. with open("Games_Pending.txt", "a", newline="") as file:
  150. writer = csv.writer(file)
  151.  
  152. rowToWrite = [game, userName]
  153. writer.writerow(rowToWrite)
  154. x = True
  155. return ["'{0}' has been suggested successfully. Gotta wait for Cloutboy to approve it.".format(game), x]
  156.  
  157. # Command to add user to points list
  158. @client.command(name = "AddUser",
  159. description = "Adds a user to the points document",
  160. brief = "Add <member> to doc",
  161. aliases = ["UserAdd", "InitUser", "adduser", "useradd", "inituser", "auser", "aUser"]
  162. )
  163. async def AddUser(ctx, member : discord.Member):
  164. if ctx.message.author.id == 142485371987427328:
  165. if initUser(member):
  166. await ctx.send("<@{0}> has been added to the list".format(member.id))
  167. await ctx.send("They have started with 0 points.")
  168. else:
  169. await ctx.send("Member is already in the list.")
  170. else:
  171. await ctx.send("You don't have permission to use that command.")
  172.  
  173. # Command to delete user from points list
  174. @client.command(name = "DelUser",
  175. description = "Deletes a user to the points document",
  176. brief = "Delete <member> from doc",
  177. aliases = ["UserDel", "deluser", "userdel", "duser", "dUser"]
  178. )
  179. async def DelUser(ctx, member : discord.Member):
  180. if ctx.message.author.id == 142485371987427328:
  181. if delUser(member):
  182. await ctx.send("{0} has been deleted from the database".format(member.name))
  183. else:
  184. await ctx.send("Member is not in the list.")
  185. else:
  186. await ctx.send("You don't have permission to use that command.")
  187.  
  188. # Command to give a user points
  189. @client.command(name = "Award",
  190. description = "Award a member x points",
  191. brief = "Award points",
  192. aliases = ["award", "reward", "givepoints", "GivePoints", "Reward"]
  193. )
  194. async def award(ctx, member : discord.Member, points):
  195. if ctx.message.author.id == 142485371987427328:
  196.  
  197. try:
  198. if int(points) < 1:
  199. raise ValueError
  200.  
  201. initUser(member)
  202. with open("Points_List.txt", "r", newline='') as file:
  203. reader = csv.reader(file)
  204. lines = list(reader)
  205.  
  206. for row in lines:
  207. if row[1] == str(member.id):
  208. newRow = row
  209. temp = (int(row[2]) + (int(points)))
  210. newRow[2] = temp
  211. rowIndex = lines.index(row)
  212.  
  213. lines[rowIndex] = newRow
  214. with open("Points_List.txt", "w", newline='') as file:
  215. writer = csv.writer(file)
  216. writer.writerows(lines)
  217.  
  218. single = 'points'
  219. if points == '1':
  220. single = 'point'
  221.  
  222. await ctx.send("{0} has been awarded {1} {2}. They now have {3}".format(member.mention, points, single, temp))
  223.  
  224. except ValueError:
  225. await ctx.send("That's not a valid argument (Must be an integer above 0).")
  226. else:
  227. await ctx.send("You don't have permission to use that command.")
  228.  
  229. # Command to take away points
  230. @client.command(name = "Punish",
  231. description = "Take x points away from a member",
  232. brief = "Take points",
  233. aliases = ["punish", "take", "takepoints", "TakePoints", "Take"]
  234. )
  235. async def punish(ctx, member : discord.Member, points):
  236. if ctx.message.author.id == 142485371987427328:
  237. try:
  238. if int(points) < 1:
  239. raise ValueError
  240.  
  241. initUser(member)
  242. with open("Points_List.txt", "r", newline='') as file:
  243. reader = csv.reader(file)
  244. lines = list(reader)
  245.  
  246. for row in lines:
  247. if row[1] == str(member.id):
  248. newRow = row
  249. temp = (int(row[2]) - (int(points)))
  250. newRow[2] = temp
  251. rowIndex = lines.index(row)
  252.  
  253. lines[rowIndex] = newRow
  254. with open("Points_List.txt", "w", newline='') as file:
  255. writer = csv.writer(file)
  256. writer.writerows(lines)
  257.  
  258. single = 'points'
  259. if points == '1':
  260. single = 'point'
  261.  
  262. await ctx.send("{0} has lost {1} {2}. They now have {3}".format(member.mention, points, single, temp))
  263.  
  264. except ValueError:
  265. await ctx.send("That's not a valid number (Must be an integer above 0).")
  266. else:
  267. await ctx.send("You don't have permission to use that command.")
  268.  
  269. # Command to check user's points
  270. @client.command(name = "Points",
  271. description = "Check how many points a user has",
  272. brief = "Check points",
  273. aliases =["points", 'check', 'Check']
  274. )
  275. async def points(ctx, member : discord.Member = None):
  276. if member:
  277. initUser(member)
  278. with open("Points_List.txt", "r", newline="") as file:
  279. for row in csv.reader(file):
  280. if row[1] == str(member.id):
  281. points = row[2]
  282.  
  283. single = 'points'
  284. if points == '1':
  285. single = 'point'
  286. await ctx.send("{0} has {1} {2}.".format(member.name, points, single))
  287.  
  288. else:
  289. initUser(ctx.message.author)
  290. with open("Points_List.txt", "r", newline='') as file:
  291. for row in csv.reader(file):
  292. if row[0] == ctx.message.author.name:
  293. points = row[2]
  294.  
  295. single = 'points'
  296. if points == '1':
  297. single = 'point'
  298. await ctx.send("{0}, you have {1} {2}.".format(ctx.message.author.mention, points, single))
  299.  
  300. # Command to reset all users' points
  301. @client.command(name = "ResetPoints",
  302. description = "Sets all users' points to 0",
  303. brief = "Reset all points",
  304. aliases = ["resetpoints"]
  305. )
  306. async def resetPoints(ctx):
  307. if ctx.message.author.id == 142485371987427328:
  308. await ctx.send("This will set all users' points to 0. Are you sure? (y/n)")
  309. def pred(m):
  310. return m.author == ctx.message.author and m.channel == ctx.message.channel
  311. sure = await client.wait_for("message", check=pred)
  312.  
  313. if sure.content == 'y':
  314. with open("Points_List.txt", "r", newline="") as file:
  315. data = list(csv.reader(file))
  316.  
  317. for row in data:
  318. data[data.index(row)][2] = 0
  319.  
  320. with open("Points_List.txt", "w", newline="") as file:
  321. writer = csv.writer(file)
  322. writer.writerows(data)
  323. await ctx.send("Successfully reset all points.")
  324. elif sure.content == "n":
  325. await ctx.send("Then why did you invoke this command? smh")
  326. else:
  327. return
  328. else:
  329. await ctx.send("You don't have permission to use that command.")
  330.  
  331. # Command to add a reward to the list
  332. @client.command(name = "NewReward",
  333. description = "Adds a new reward that user's can redeem",
  334. brief = "Add new reward",
  335. aliases = ["AddR", "addreward", "AddReward", "newreward", "addr"]
  336. )
  337. async def NewReward(ctx, *args):
  338. if ctx.message.author.id == 142485371987427328:
  339.  
  340. if len(args) == 0:
  341. await ctx.send("You can't have a reward with no name.")
  342. return
  343.  
  344. rewardName = " ".join(args)
  345.  
  346. with open("Rewards_List.txt", "r", newline = "") as file:
  347. for row in csv.reader(file):
  348. if row[0] == rewardName:
  349. await ctx.send("That reward is already on the list. If you wish to change it, you'll need to delete the existing one first.")
  350. return
  351.  
  352. await ctx.send("Please write a short description of the reward. (Type '#cancel# to cancel this reward)")
  353. def pred(m):
  354. return m.author == ctx.message.author and m.channel == ctx.message.channel
  355. rewardDesc = await client.wait_for("message", check=pred)
  356.  
  357. if rewardDesc.content == "#cancel#":
  358. await ctx.send("Cancelled the reward-creator.")
  359. return
  360.  
  361. await ctx.send("And how many points will it take to redeem this reward? (Type '#cancel#' to cancel this reward)")
  362. rewardCost = await client.wait_for("message", check=pred)
  363.  
  364. if rewardCost.content == "#cancel#":
  365. await ctx.send("Cancelled the reward-creator.")
  366. return
  367.  
  368. try:
  369. rewardCost = int(rewardCost.content)
  370. except ValueError:
  371. await ctx.send("That's not a valid price (Must be an integer more than 0).")
  372. return
  373. if rewardCost < 1:
  374. await ctx.send("That's not a valid price (Must be an integer more than 0).")
  375. return
  376.  
  377. with open("Rewards_List.txt", "a", newline="") as file:
  378. writer = csv.writer(file)
  379. writer.writerow([rewardName, rewardCost, rewardDesc.content])
  380.  
  381. await ctx.send("Reward '{0}' succesfully added to list.".format(rewardName))
  382. else:
  383. await ctx.send("You don't have permission to use that command.")
  384.  
  385. # Command to delete a reward
  386. @client.command(name = "DelReward",
  387. description = "Deletes a redeemable reward from the list",
  388. brief = "Delete a reward",
  389. aliases = ["DelR", "delr", "delreward"]
  390. )
  391. async def DeleteReward(ctx, *args):
  392. if ctx.message.author.id == 142485371987427328:
  393. if len(args) == 0:
  394. await ctx.send("You have to specify a reward to delete.")
  395. else:
  396. with open("Rewards_List.txt", "r", newline='') as file:
  397. data = list(csv.reader(file))
  398.  
  399. deleted = False
  400. reward = " ".join(args)
  401.  
  402. with open("Rewards_List.txt", "w", newline='') as file:
  403. writer = csv.writer(file)
  404. for row in data:
  405. if row[0] == reward:
  406. deleted = True
  407. else:
  408. writer.writerow(row)
  409.  
  410. if deleted:
  411. await ctx.send("'{0}' has been successfully deleted.".format(" ".join(args)))
  412. else:
  413. await ctx.send("There is no reward by that name.")
  414. else:
  415. await ctx.send("You don't have permission to use that command.")
  416.  
  417. # Command that lists all rewards
  418. @client.command(name = "Rewards",
  419. description = "List all the redeemable rewards",
  420. brief = "List all rewards",
  421. aliases = ["rewards"]
  422. )
  423. async def rewards(ctx):
  424. initUser(ctx.message.author)
  425. with open("Rewards_List.txt", "r", newline="") as file:
  426. thingtosay = ""
  427. for row in csv.reader(file):
  428. thingtosay += f"------------------------------------------------\n{row[0]} | {row[2]}\n{row[1]} points\n"
  429.  
  430. thingtosay += f"------------------------------------------------\nUse c!games to see the list of nominated games you can vote for.\n------------------------------------------------\nUse c!redeem <reward> to redeem a reward."
  431. await ctx.send(thingtosay)
  432.  
  433. # Command to add/suggest a game to the list
  434. @client.command(name = "Nominate",
  435. description = "Nominate a game to be voted for (Only two nominations per user)",
  436. brief = "Nominate a game",
  437. aliases = ["nominate"]
  438. )
  439. async def nominate(ctx, *args):
  440. initUser(ctx.message.author)
  441. game = " ".join(args)
  442. result = addGame(game, ctx.message.author.id, ctx.message.author.name)
  443.  
  444. if type(result) is list:
  445. await ctx.send(result[0])
  446. cloutboy = client.get_user(142485371987427328)
  447. await cloutboy.send("The game '{0}' has been suggested by {1}. Type 'c!Accept {0}' or c!Reject {0}'.".format(game, ctx.message.author.name))
  448. else:
  449. await ctx.send(result)
  450.  
  451. # Command to accept a suggestion
  452. @client.command(name = "Accept",
  453. description = "Accept a game suggestion",
  454. brief = "Accept a game suggestion",
  455. aliases = ["accept"]
  456. )
  457. async def Accept(ctx, *args):
  458. if ctx.message.author.id == 142485371987427328:
  459. game = " ".join(args)
  460.  
  461. with open("Games_Pending.txt", "r", newline="") as file:
  462. found = False
  463. for row in csv.reader(file):
  464. if row[0].capitalize() == game.capitalize():
  465. found = True
  466.  
  467. if found == False:
  468. await ctx.send("'{0}' is not on the suggestions list.".format(game))
  469. return
  470.  
  471. result = addGame(game, ctx.message.author.id, ctx.message.author.name)
  472. await ctx.send(result)
  473. else:
  474. await ctx.send("You don't have permisssion to use this command")
  475.  
  476. # Command to reject a suggestion/delete a game
  477. @client.command(name = "Reject",
  478. description = "Reject a game suggestion",
  479. brief = "Reject a game suggestion",
  480. aliases = ["reject"]
  481. )
  482. async def Reject(ctx, *args):
  483. game = " ".join(args)
  484.  
  485. if ctx.message.author.id == 142485371987427328:
  486. with open("Games_Pending.txt", "r", newline="") as file:
  487. data = list(csv.reader(file))
  488.  
  489. with open("Games_Pending.txt", "w", newline="") as file:
  490. writer = csv.writer(file)
  491. found = False
  492. for row in data:
  493. if row[0].capitalize() == game.capitalize():
  494. found = True
  495. rowtowrite = row
  496. rowtowrite.append("Rejected")
  497. writer.writerow(rowtowrite)
  498. else:
  499. writer.writerow(row)
  500.  
  501. with open("Games_List.txt", "r") as file:
  502. data = list(csv.reader(file))
  503.  
  504. with open("Games_List.txt", "w", newline="") as file:
  505. writer = csv.writer(file)
  506. foundB = False
  507. for row in data:
  508. if row[0].capitalize() == game.capitalize():
  509. foundB = True
  510. else:
  511. writer.writerow(row)
  512.  
  513. if found and (not foundB):
  514. await ctx.send("'{0}' has been rejected successfully.".format(game))
  515. elif foundB:
  516. with open("Games_Pending.txt", "a", newline="") as file:
  517. csv.writer(file).writerow([game, "Deleted"])
  518.  
  519. await ctx.send("'{0}' has been deleted from the Games List".format(game))
  520. else:
  521. await ctx.send("'{0}' is not in the pending list.".format(game))
  522.  
  523. # Command to list all games in Games_List
  524. @client.command(name = "Games",
  525. description = "Shows all the games that can be voted for",
  526. brief = "List all games in the list",
  527. aliases = ["games"]
  528. )
  529. async def Games(ctx, votes=None):
  530. with open("Games_List.txt", "r") as file:
  531. reader = csv.reader(file)
  532.  
  533. if ctx.message.author.id == 142485371987427328:
  534. if votes == 'votes' or votes == 'Votes':
  535.  
  536. rowToSay = ""
  537. for row in reader:
  538. if row[1] == '1':
  539. single = 'point'
  540. else:
  541. single = 'points'
  542.  
  543. rowToSay += "------------------------------------------------\n{0} | {1} {2}\n".format(row[0], row[1], single)
  544. rowToSay += "------------------------------------------------\nUsers can type 'c!vote <game>' to vote. They can vote as many times as they wish."
  545. await ctx.send(rowToSay)
  546. return
  547.  
  548. initUser(ctx.message.author)
  549. rowToSay = ""
  550. for row in reader:
  551. rowToSay += "------------------------------------------------\n{0}\n".format(row[0])
  552. rowToSay += "------------------------------------------------\nYou can vote for a game with 'c!vote <game>'. You can vote as many times as you wish."
  553. await ctx.send(rowToSay)
  554.  
  555. # Command to reset games
  556. @client.command(name = "ResetGames",
  557. description = "Reset the Games list and the pending list",
  558. brief = "Delete all games in the lists",
  559. aliases = ["resetgames"]
  560. )
  561. async def resetGames(ctx):
  562. if ctx.message.author.id == 142485371987427328:
  563. await ctx.send("This will delete all of the games in Games_List and Games_Pending, are you sure? (y/n)")
  564. def pred(m):
  565. return m.author == ctx.message.author and m.channel == ctx.message.channel
  566. sure = await client.wait_for("message", check=pred)
  567.  
  568. if sure.content == 'y' or sure.content == 'Y':
  569. with open("Games_List.txt", "w"):
  570. print("reset games_list")
  571. with open("Games_Pending.txt", "w"):
  572. print("reset games_pending")
  573.  
  574. await ctx.send("Succesfully reset.")
  575. elif sure.content == 'n' or sure.content == 'N':
  576. await ctx.send("Then why did you invoke this command? smh")
  577. else:
  578. await ctx.send("???")
  579.  
  580. # Command to add points to a game
  581. @client.command(name = "Vote",
  582. description = "Vote for the game you want Cloutboy to play next",
  583. brief = "Vote for a game",
  584. aliases = ["vote"]
  585. )
  586. async def Vote(ctx, *args):
  587.  
  588. initUser(ctx.message.author)
  589.  
  590. game = " ".join(args)
  591. with open("Games_List.txt", "r") as file:
  592. found = False
  593. for row in csv.reader(file):
  594. if row[0].capitalize() == game.capitalize():
  595. found = True
  596.  
  597. if found:
  598. with open("Points_List.txt", "r") as file:
  599. reader = csv.reader(file)
  600. data = list(reader)
  601. for row in data:
  602. if row[0] == ctx.message.author.name:
  603. points = int(row[2])
  604.  
  605. if points == '1':
  606. single = 'point'
  607. else:
  608. single = 'points'
  609. def pred(m):
  610. return m.author == ctx.message.author and m.channel == ctx.message.channel
  611. await ctx.send("{0}, how many points would you like to add to this game's pool? (You have {1} {2} left)".format(ctx.message.author.mention, points, single))
  612. vote = await client.wait_for("message", check=pred)
  613.  
  614. try:
  615. vote = int(vote.content)
  616. if vote <= 0:
  617. raise ValueError
  618.  
  619. except ValueError:
  620. await ctx.send("That's not a valid amount.")
  621. return
  622.  
  623. if vote > points:
  624. await ctx.send("You don't have enough points.")
  625. return
  626.  
  627. for row in data:
  628. if row[0] == ctx.message.author.name:
  629. newRow = row
  630. temp = (int(row[2]) - (int(vote)))
  631. newRow[2] = temp
  632. rowIndex = data.index(row)
  633.  
  634. data[rowIndex] = newRow
  635. with open("Points_List.txt", "w", newline='') as file:
  636. writer = csv.writer(file)
  637. writer.writerows(data)
  638.  
  639.  
  640. with open("Games_List.txt", "r", newline='') as file:
  641. reader = csv.reader(file)
  642. lines = list(reader)
  643.  
  644. for row in lines:
  645. if row[0] == game:
  646. newRow = row
  647. temp = (int(row[1]) + (int(vote)))
  648. newRow[1] = temp
  649. rowIndex = lines.index(row)
  650.  
  651. lines[rowIndex] = newRow
  652. with open("Games_List.txt", "w", newline='') as file:
  653. writer = csv.writer(file)
  654. writer.writerows(lines)
  655.  
  656. if vote == 1:
  657. single = 'point'
  658. else:
  659. single = 'points'
  660.  
  661. await ctx.send("{0}, you have added {1} {2} to '{3}'".format(ctx.message.author.mention, vote, single, game))
  662.  
  663. else:
  664. await ctx.send("'{0}' is not in the list.".format(game))
  665.  
  666. # Command to show top 3 games
  667. @client.command(name = "Top",
  668. description = "Show the top voted-for games",
  669. brief = "Show top games",
  670. aliases = ["top"]
  671. )
  672. async def top3(ctx):
  673. if ctx.message.author.id == 142485371987427328:
  674. with open("Games_List.txt", "r") as file:
  675. data = list(csv.reader(file))
  676. data.sort(key = itemgetter(1), reverse = True)
  677. try:
  678. top = [data[0], data[1], data[2]]
  679. except IndexError:
  680. try:
  681. top = [data[0], data[1]]
  682. except IndexError:
  683. try:
  684. top = [data[0]]
  685. except IndexError:
  686. await ctx.send("There are no games in the list.")
  687. return
  688. thingToSay = ''
  689. for row in top:
  690. if row[1] == '1':
  691. single = 'vote'
  692. else:
  693. single = 'votes'
  694.  
  695. thingToSay += "------------------------------------------------\n{0} | {1} {2}\n".format(row[0], row[1], single)
  696. thingToSay += "------------------------------------------------"
  697. await ctx.send(thingToSay)
  698.  
  699. else:
  700. await ctx.send("You don't have permission to use this command.")
  701.  
  702. # Command to redeem custom rewards
  703. @client.command(name = "Redeem",
  704. description = "Redeem a reward from the custom list",
  705. brief = "Redeem a reward",
  706. aliases = ["redeem", "buy", "Buy"]
  707. )
  708. async def redeem(ctx, *args):
  709. initUser(ctx.message.author)
  710. reward = " ".join(args)
  711.  
  712. with open("Rewards_List.txt", "r") as file:
  713. found = False
  714. for row in csv.reader(file):
  715. if row[0].capitalize() == reward.capitalize():
  716. found = True
  717. price = int(row[1])
  718.  
  719. if not found:
  720. await ctx.send("That reward is not in the list.")
  721. return
  722. else:
  723. await ctx.send(f"Redeem '{reward}'' for {price}? (y/n)")
  724. def pred(m):
  725. return m.author == ctx.message.author and m.channel == ctx.message.channel
  726. sure = await client.wait_for("message", check=pred)
  727. if sure.content != "y" and sure.content != "Y":
  728. await ctx.send("Canceled redemption.")
  729. return
  730.  
  731. with open("Points_List.txt", "r") as file:
  732. reader = csv.reader(file)
  733. lines = list(reader)
  734.  
  735. for row in lines:
  736. if row[1] == str(ctx.message.author.id):
  737. newRow = row
  738. temp = int(row[2]) - price
  739. if temp < 0:
  740. await ctx.send("You don't have enough points.")
  741. return
  742.  
  743. newRow[2] = temp
  744. rowIndex = lines.index(row)
  745.  
  746. lines[rowIndex] = newRow
  747. with open("Points_List.txt", "w", newline='') as file:
  748. writer = csv.writer(file)
  749. writer.writerows(lines)
  750.  
  751. if price == 1:
  752. single = 'point'
  753. else:
  754. single = 'points'
  755.  
  756. await ctx.send(f"{ctx.message.author.mention}, succesfully redeemed '{reward}' for {price} {single}. You now have {temp}.")
  757.  
  758. cloutboy = client.get_user(142485371987427328)
  759. await cloutboy.send(f"{ctx.message.author.name} has redeemed '{reward}' for {price} {single}.")
  760.  
  761. # CHECK IF KEYWORD IN MESSAGE
  762. def KeywordInMessage(word):
  763. return re.compile(r'\b({0})\b'.format(word), flags=re.IGNORECASE).search
  764.  
  765. @client.event
  766. async def on_message(message):
  767. if message.author == client.user:
  768. return # Don't reply to self
  769.  
  770. if KeywordInMessage("daddy")(message.content):
  771. await message.channel.send("UwU")
  772. await asyncio.sleep(0.5)
  773.  
  774. elif KeywordInMessage("UwU")(message.content):
  775. await message.channel.send("Daddy")
  776. await asyncio.sleep(0.5)
  777.  
  778. # Allow for commands to be processed while on_message occurs
  779. await client.process_commands(message)
  780.  
  781.  
  782. # Stuff that happens on startup
  783. @client.event
  784. async def on_ready():
  785. await client.change_presence(status=discord.Status.idle, activity=Game(helpCommand))
  786. print('Logged in as:')
  787. print(client.user.name)
  788. print(client.user.id)
  789. print('------')
  790.  
  791. # Actually run the damn thing
  792. client.run(TOKEN)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement