-
Notifications
You must be signed in to change notification settings - Fork 0
/
ccbot_logger.py
81 lines (64 loc) · 2.38 KB
/
ccbot_logger.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
#!/bin/python3 -u
import discord
import os
from dotenv import load_dotenv
from discord.ext import commands
from discord.utils import get
import re
import time
import asyncio
load_dotenv()
intents = discord.Intents.all()
client = commands.Bot(command_prefix='!', intents=intents)
@client.event
async def on_ready():
print('ccbot_logger started on bot {0.user}'.format(client))
@client.event
async def on_message(message):
if message.channel.id == int(os.getenv('channel')):
if message.author == client.user:
content = str(message.content)
if content.startswith('*'):
return
rsn_ptrn = "] (.*?): "
login_ptrn = "> (.*?) has joined"
logot_ptrn = "] (.*?) has left"
emt_ptrn = "<:(.*?)>"
rsn = re.search(rsn_ptrn, content)
login = re.search(login_ptrn, content)
logot = re.search(logot_ptrn, content)
emt = re.search(emt_ptrn, content)
if login:
cc_logins = open("cc_logins.log", "a")
cc_logins.write(str(str(login.group(1)) + "\n"))
cc_logins.close()
cc_online = open("cc_online.log", "a")
cc_online.write(str(str(login.group(1)) + "\n"))
cc_online.close()
await asyncio.sleep(15)
await message.delete()
if logot:
cc_online = open("cc_online.log", "r")
cc_online_content = cc_online.readlines()
cc_online.close()
cc_online = open("cc_online.log", "w")
for logout_rsn in cc_online_content:
if logout_rsn.strip() != logot.group(1):
cc_online.write(logout_rsn)
cc_online.close()
await asyncio.sleep(15)
await message.delete()
if rsn:
if emt:
emt_full = str("<:" + str(emt.group(1)) + ">")
rsn = str(rsn.group(1)).replace(emt_full, "")
else:
rsn = rsn.group(1)
cc_messages = open("cc_messages.log", "a")
cc_messages.write(str(rsn + "\n"))
cc_messages.close()
else:
print(message.author,":",message.content)
else:
return
client.run(os.getenv('TOKEN'))