Advertisement
xmann110

Untitled

Mar 2nd, 2020
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. import discord
  2. import time
  3.  
  4. token = ""
  5.  
  6. client = discord.Client()
  7.  
  8.  
  9. @client.event
  10. async def on_ready():
  11. print("Bot started")
  12.  
  13.  
  14. @client.event
  15. async def on_message(ctx):
  16. print(ctx.guild.name, ctx.content)
  17. corona_role = None
  18.  
  19. if ctx.author.id == client.user.id:
  20. return
  21.  
  22. for role in ctx.guild.roles:
  23. if role.name == "Corona infected":
  24. corona_role = role
  25. print("Found existing Corona role")
  26. break
  27.  
  28. if corona_role is None:
  29. print("Creating new Corona role")
  30. try:
  31. corona_role = await ctx.guild.create_role(name="Corona infected", color=discord.Color(0xff0000))
  32. await ctx.guild.get_member(client.user.id).add_roles(corona_role)
  33. await ctx.channel.send("Corona virus has now been detected on this server.")
  34. print("Corona role created")
  35. except PermissionError:
  36. print("No permission to create Corona role")
  37. if ctx.guild.id not in warned:
  38. await ctx.channel.send("I do not have permission to manage roles.")
  39. warned.append(ctx.guild.id)
  40. else:
  41. print("WARNING: SILENTLY FAILED IN " + ctx.guild.name)
  42.  
  43. return
  44.  
  45. if not ctx.author in corona_role.members:
  46. print("Author is not infected")
  47. prev = None
  48. async for message in ctx.channel.history(limit=2):
  49. if prev is None:
  50. prev = message
  51. continue
  52.  
  53. if "You are now infected" in message.content:
  54. return
  55.  
  56. if "You barely" in message.content:
  57. return
  58.  
  59. time_since = ctx.created_at.timestamp() - message.created_at.timestamp()
  60.  
  61. print(f"Last message by {message.author.name} {time_since} seconds ago")
  62.  
  63. if message.author in corona_role.members and time_since < 5 * 60:
  64. print("Infected!")
  65. await ctx.channel.send("<:corona:684132221077946401><:corona:684132221077946401><:corona:684132221077946401> **UH OH! You are now infected with the Corona virus** <:corona:684132221077946401><:corona:684132221077946401><:corona:684132221077946401>")
  66. await ctx.author.add_roles(corona_role)
  67. elif time_since < 8 * 60:
  68. print("Barely no infection")
  69. await ctx.channel.send("<:corona:684132221077946401><:corona:684132221077946401><:corona:684132221077946401> **You barely escaped infection!** <:corona:684132221077946401><:corona:684132221077946401><:corona:684132221077946401>")
  70. else:
  71. print("No infection")
  72.  
  73.  
  74. warned = []
  75.  
  76. client.run(token)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement