-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbot.py
146 lines (119 loc) · 4.19 KB
/
bot.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
import discord, os, json
from datetime import datetime
from __main__ import CCHangelogFile, ResName
Testing = False
intents = discord.Intents()
intents.guilds = True
intents.members = True
intents.bans = False
intents.emojis = True
intents.integrations = True
intents.webhooks = False
intents.invites = True
intents.voice_states = False
intents.presences = False
intents.messages = True
intents.guild_messages = True
intents.dm_messages = True
intents.reactions = True
intents.guild_reactions = True
intents.dm_reactions = True
intents.typing = True
intents.guild_typing = True
intents.dm_typing = False
bot = discord.Client(intents=intents)
abs = os.path.abspath( '' )
TOKEN = ''
JSON = {}
ResourceName = ''
with open( f'{abs}/BOT.json', 'r' ) as f:
JSON = json.load( f )
f.close()
async def SendMessage( guild, channel, message ):
# If i want to test something before commiting to other servers
if Testing and guild.id != 1145236064596918304:
return
try:
msg = await channel.send( f'{message}')
if msg:
print( f'Sent to "{guild.name}"' )
if JSON:
for e in JSON.get( "reactions" ):
await msg.add_reaction( e )
except Exception as e:
pr=0
async def PrepareMessage( guild, channel ):
guild: discord.guild
channel: discord.channel
Message = ''
if ResName != 'bot':
if CCHangelogFile and CCHangelogFile != '':
# Check just in case, i'm dumb :$
if not Testing:
token = os.getenv( "BOT" )
if token == "" or not token:
return
fechan = datetime.now()
fecha = fechan.strftime("%d/%m/%y")
AnythingNew = False
with open( CCHangelogFile, 'r' ) as f:
lines = f.readlines()
for line in lines:
if line.startswith( "<details><summary>" ):
line = line[ 18: ]
if line.startswith( f'latest {fecha}' ):
AnythingNew = True
Message = f'# {ResName}\n### {fecha}'
continue
if AnythingNew:
if line.startswith('---'):
break
Message = f'{Message}{line}'
f.close()
if Message and Message != '':
Message = f'{Message}\n[Download Here](https://github.com/Mikk155/Sven-Co-op/releases/tag/{ResName}/svencoop.zip)'
await SendMessage( guild, channel, Message )
else:
with open( f'{abs}/BOT.md', 'r' ) as f:
lines = f.readlines()
for l in lines:
Message = f'{Message}{l}'
f.close()
if Message and Message != '':
await SendMessage( guild, channel, Message )
async def GetChannels( guild ):
guild: discord.guild
for channel in guild.channels:
if channel and isinstance( channel, discord.TextChannel ):
description = channel.topic
if not description or description == None:
continue
if 'mikk155/sven-co-op' in description.lower():
await PrepareMessage( guild, channel )
@bot.event
async def on_ready():
print('Initialising BOT {0.user}'.format( bot ) )
for guild in bot.guilds:
print( f'Getting Server "{guild.name}"')
await GetChannels( guild )
await bot.close()
def InitBot():
# I don't recall what this is but this bot for sure doesn't exists anymore.
if True:
return
File = os.path.join( abs, 'BOT.txt' )
if os.path.exists( File ):
with open( f'{File}' ) as token:
TOKEN = token.readline()
bot.run( TOKEN )
else:
try:
token = os.getenv( "BOT" )
if token == "" or not token:
raise Exception("Please add your token \"BOT\" to the Secrets panel.")
bot.run(token)
except discord.HTTPException as e:
if e.status == 429:
print( "The Discord servers denied the connection for making too many requests" )
else:
raise e