-
Notifications
You must be signed in to change notification settings - Fork 0
/
ping.py
147 lines (114 loc) · 4.75 KB
/
ping.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import disnake
from disnake.ext import commands
from dotenv import load_dotenv
import random
import time
import os
from helpers import log
# Load the token from the .env file
load_dotenv()
TOKEN = os.getenv("ROLES_DISCORD_TOKEN")
TEST_GUILDS = os.getenv("TEST_GUILD")
TARGET_MEMBER = os.getenv("PING_TARGET")
intents = disnake.Intents.default()
intents.members = True
intents.presences = True
intents.message_content = True
# ! We do a little trolling
# ! (Just a bit)
# ! This bot pings a specific user when they go offline to mimic an event happening *just* after they went offline.
bot = commands.InteractionBot(test_guilds=TEST_GUILDS, intents=intents)
def create_embed() -> disnake.Embed:
embed = disnake.Embed(title="Vex Incursion Incoming!",
colour=0xb6dd62)
embed.add_field(name="Incursion starts in",
value=f"<t:{int(time.time()) + 285}:R>",
inline=False)
embed.add_field(name="Location",
value="Zephyr Concourse",
inline=False)
embed.add_field(name="Support me and help me keep the bot running!",
value="https://ko-fi.com/buuz135",
inline=False)
embed.set_thumbnail(url="https://media.discordapp.net/attachments/1100800542978097253/1104429284430450758/02E4-01FA.png")
embed.set_footer(text="Vex Network",
icon_url="https://media.discordapp.net/attachments/1100800542978097253/1104424186895671387/0332-07FE.png")
return embed
@bot.event
async def on_presence_update(before: disnake.Member, after: disnake.Member):
if after.id == TARGET_MEMBER and before.guild.id == TEST_GUILDS[0] and after.guild.id == TEST_GUILDS[0]:
log(f"{after.display_name} is now {after.status} from {before.status} with {before._client_status}.")
if not after.status == disnake.Status.offline:
return
if not before.desktop_status == disnake.Status.online:
return
# 1/15 chance of happening
r = random.randint(1, 15)
if r != 1:
log(f'\tFailed roll {r=}.')
return
log('\tSucceeded roll!')
# wait some time between 20 seconds and 2 minutes
t = random.randint(20, 120)
log(f'\tWaiting {t} seconds to start...')
time.sleep(t)
# check if the target is still offline
if not (await after.guild.fetch_member(after.id)).status == disnake.Status.offline:
return
bot_original_nickname = bot.user.display_name
# create the role
role = await after.guild.create_role(name="Harpy")
# add the target to the role
await after.add_roles(role)
# create a channel only visible to bot and the target
channel = await after.guild.create_text_channel(
name="vex-incursion", overwrites={after.guild.default_role: disnake.PermissionOverwrite(read_messages=False),
role: disnake.PermissionOverwrite(read_messages=True)})
# change bot's nickname to a temporary one
bot_member = after.guild.get_member(bot.user.id);
assert bot_member
await bot_member.edit(nick="Asher Mir")
# send a message to the channel, pinging the role
await channel.send(f"{role.mention}", embed=create_embed())
time.sleep(3)
# delete the channel
try:
await channel.delete()
log('\tCleaned up channel.')
except:
log('\tFailed to clean up channel.')
log('\tRetrying...')
time.sleep(2)
try:
await channel.delete()
log('\tCleaned up channel.')
except:
log('\tFailed to clean up channel.')
# delete the role
try:
await role.delete()
log('\tCleaned up role.')
except:
log('\tFailed to clean up role.')
log('\tRetrying...')
time.sleep(2)
try:
await role.delete()
log('\tCleaned up role.')
except:
log('\tFailed to clean up role.')
# change bot's nickname back to normal
try:
await bot_member.edit(nick=bot_original_nickname)
log('\tChanged bot\'s nickname back to normal.')
except:
log('\tFailed to change bot\'s nickname back to normal.')
log('\tRetrying...')
time.sleep(2)
try:
await bot_member.edit(nick=bot_original_nickname)
log('\tChanged bot\'s nickname back to normal.')
except:
log('\tFailed to change bot\'s nickname back to normal.')
log('\tDone!')
bot.run(TOKEN)