forked from astroid-app/api-main
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror-correction.py
116 lines (111 loc) · 6.07 KB
/
error-correction.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
import traceback
import nextcord
import json
from nextcord.ext import commands, tasks
import config
import asyncio
import os
class error_correction(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.error_correction_loop.start()
@tasks.loop()
async def error_correction_loop(self):
while True:
try:
for filename in os.listdir('api'):
if filename.endswith('.json'):
_guildid = filename[:-5]
api_raw = open(f"api/{_guildid}.json")
api = json.load(api_raw)
state = api["general"][0]["state"]
int_state = int(state)
if int_state != 0:
if int_state != 1:
embed = nextcord.Embed(title=f"State error in {_guildid}",
description=f"```py\n State was set to {state}```")
error_log_channel = self.bot.get_channel(config.ERR_LOG_CHANNEL_ID)
await error_log_channel.send(embed=embed)
discord_id = api["general"][0]["discord_id"]
guilded_id = api["general"][0]["guilded_id"]
discord_channel = api["general"][0]["discord_channel"]
guilded_channel = api["general"][0]["guilded_channel"]
data = {
'general': [
{
'discord_id': f'{discord_id}',
'guilded_id': f'{guilded_id}',
'state': '0',
'sender': '',
'receiver': '',
'discord_channel': f'{discord_channel}',
'guilded_channel': f'{guilded_channel}',
}
],
'meta': [
{
'text': '',
"author-profile": "",
'sender': '',
}
]
}
api_raw.close()
f = open(f"api/{_guildid}.json", "w")
json.dump(data, f)
f.close()
sender = api["general"][0]["sender"]
if sender is None or "":
pass
else:
if sender != "discord":
if sender != "guilded":
embed = nextcord.Embed(title=f"Sender error in {_guildid}",
description=f"```py\n Sender was set to {sender}```")
error_log_channel = self.bot.get_channel(config.ERR_LOG_CHANNEL_ID)
await error_log_channel.send(embed=embed)
state_correction = api["general"][0]["state"]
discord_id = api["general"][0]["discord_id"]
guilded_id = api["general"][0]["guilded_id"]
discord_channel = api["general"][0]["discord_channel"]
guilded_channel = api["general"][0]["guilded_channel"]
data = {
'general': [
{
'discord_id': f'{discord_id}',
'guilded_id': f'{guilded_id}',
'state': f'{state_correction}',
'sender': None,
'receiver': '',
'discord_channel': f'{discord_channel}',
'guilded_channel': f'{guilded_channel}',
}
],
'meta': [
{
'text': '',
"author-profile": "",
'sender': '',
'cdn':
{
"is-cdn": True,
"attachments": [
{
"url": "https://raw.githubusercontent.com/Guildcord-API/api-main/main/logo.png"
}
]
}
}
]
}
api_raw.close()
f = open(f"api/{_guildid}.json", "w")
json.dump(data, f)
f.close()
except:
pass
traceback.print_exc()
await asyncio.sleep(1)
def setup(bot):
bot.add_cog(error_correction(bot))
print("[ Discord node ][ Guildcord - COG ] Started error-correction.")