qsadfasdgfgads

Untitled

Apr 15th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. import discord
  2. import re
  3. from tinydb import TinyDB
  4. import asyncio
  5.  
  6.  
  7. async def my_background_task():
  8. print("Started!")
  9. await client.wait_until_ready()
  10. while client.is_closed:
  11. with open("stats.txt", "a") as f:
  12. f.write("Hello\n")
  13. print("Wrote!")
  14. await asyncio.sleep(5) # task runs every 60 seconds
  15.  
  16.  
  17. class MyClient(discord.Client):
  18. async def on_ready(self):
  19. print("Logged as {0}!".format(self.user))
  20.  
  21. def recognize(self, test_str):
  22. regex = r"--(\w+)=([^--]+)"
  23. matches = re.findall(regex, test_str)
  24. return matches
  25.  
  26. async def on_message(self, message):
  27. print("Message from {0.author}: {0.content}".format(message))
  28. text = message.content.lower()
  29. if "!разослать" in text and message.author.bot is False:
  30. b = client.get_guild(699352136273887292)
  31. users = []
  32. for member in b.members:
  33. user = client.get_user(member.id)
  34. if user.bot:
  35. continue
  36. users.append(str(member.id))
  37. print(users)
  38. params = {'users': ','.join(users)}
  39. recognize_objects = self.recognize(text)
  40. for obj in recognize_objects:
  41. params[obj[0].strip()] = obj[1].strip()
  42. db = TinyDB('db.json')
  43. db.insert(params)
  44.  
  45.  
  46. client = MyClient()
  47. client.loop.create_task(my_background_task())
  48. client.run('token')
Advertisement
Add Comment
Please, Sign In to add comment