-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
68 lines (53 loc) · 1.82 KB
/
main.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
import os
import sys
import discord
from discord.client import _ClientEventTask
from dotenv import load_dotenv
import re
# Get the path to the directory this file is in
BASEDIR = os.path.abspath(os.path.dirname(__file__))
# Connect the path with your '.env' file name
load_dotenv(os.path.join(BASEDIR, '.env'))
TOKEN = os.getenv('DISCORD_TOKEN')
client = discord.Client()
server_id = int(os.getenv('SERVER_ID'))
bot_test = int(os.getenv('CHANNEL_ID'))
role_id = int(os.getenv('ROLE_ID'))
logString = sys.argv[1]
username_dict = {
"076561198055834108": "Trevor",
"39773": "Brian",
"4": "Jared"
}
@client.event
async def on_ready():
# print(f'{client.user} has connected to Discord!')
server = discord.utils.find(lambda g: g.id == server_id, client.guilds)
# for guild in client.guilds:
# print(
# f'{client.user} is connected to the following guild:\n'
# f'{guild.name}(id: {guild.id})'
# )
# if guild.id == server_id:
# server = guild
# print(server.id)
# print(server.channels)
channel = discord.utils.find(lambda x: x.id == bot_test, server.channels)
# print(channel)
# print(server.roles)
role = discord.utils.find(lambda x : x.id == role_id, server.roles)
# print(role)
# print(logString)
if match := re.search(r"Beacon Join .*?(\d+)", logString):
user_id = match.groups()[0]
print(role.mention)
print(user_id)
if user_id in username_dict:
# print(username_dict[user_id])
await channel.send(f"{role.mention} {username_dict[user_id]} just logged in!")
else:
# print("Unknown user")
await channel.send(f"{role.mention} Unknown user: {user_id} just logged in!")
await client.close()
if __name__ == "__main__":
client.run(TOKEN)