Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- import time
- token = ""
- client = discord.Client()
- @client.event
- async def on_ready():
- print("Bot started")
- @client.event
- async def on_message(ctx):
- print(ctx.guild.name, ctx.content)
- corona_role = None
- if ctx.author.id == client.user.id:
- return
- for role in ctx.guild.roles:
- if role.name == "Corona infected":
- corona_role = role
- print("Found existing Corona role")
- break
- if corona_role is None:
- print("Creating new Corona role")
- try:
- corona_role = await ctx.guild.create_role(name="Corona infected", color=discord.Color(0xff0000))
- await ctx.guild.get_member(client.user.id).add_roles(corona_role)
- await ctx.channel.send("Corona virus has now been detected on this server.")
- print("Corona role created")
- except PermissionError:
- print("No permission to create Corona role")
- if ctx.guild.id not in warned:
- await ctx.channel.send("I do not have permission to manage roles.")
- warned.append(ctx.guild.id)
- else:
- print("WARNING: SILENTLY FAILED IN " + ctx.guild.name)
- return
- if not ctx.author in corona_role.members:
- print("Author is not infected")
- prev = None
- async for message in ctx.channel.history(limit=2):
- if prev is None:
- prev = message
- continue
- if "You are now infected" in message.content:
- return
- if "You barely" in message.content:
- return
- time_since = ctx.created_at.timestamp() - message.created_at.timestamp()
- print(f"Last message by {message.author.name} {time_since} seconds ago")
- if message.author in corona_role.members and time_since < 5 * 60:
- print("Infected!")
- 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>")
- await ctx.author.add_roles(corona_role)
- elif time_since < 8 * 60:
- print("Barely no infection")
- await ctx.channel.send("<:corona:684132221077946401><:corona:684132221077946401><:corona:684132221077946401> **You barely escaped infection!** <:corona:684132221077946401><:corona:684132221077946401><:corona:684132221077946401>")
- else:
- print("No infection")
- warned = []
- client.run(token)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement