-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
72 lines (54 loc) · 1.99 KB
/
bot.py
File metadata and controls
72 lines (54 loc) · 1.99 KB
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
import time
import os
import datetime
import asyncio
import sys
import discord
from discord.ext import tasks
from dotenv import load_dotenv
from parsing import parse_store_fix
from markdown import generate_reports
load_dotenv()
PORTALHUB = 660524457206480964
REPORT_CHANNEL = 1084852899986821202
TEST_CHANNEL = 778458151057752084
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
API_KEY = os.getenv("HYPIXEL_API_KEY")
path = "/mnt/c/Users/alext/Downloads/mmc-stable-win32/MultiMC/instances/1.8.9/.minecraft/config/ChatTriggers/modules/stats_read/data.txt"
class Bot(discord.Client):
async def on_ready(self):
print(f"Logged on as {self.user}!")
self.fetch_queue.start()
self.publish_report.start()
self.index = 0
@tasks.loop(seconds=60)
async def fetch_queue(self):
# if the file at path has not been modified in the last minute
# send a message to portalhub to notify them
if (time.time() - os.path.getmtime(path)) > 30:
user = await self.fetch_user(PORTALHUB)
await user.send("prtl is down")
print(f"{datetime.datetime.now()} -> prtl is down")
else:
print(f"{datetime.datetime.now()} -> prtl is up")
print(f"{datetime.datetime.now()} -> Fetching prtl data...")
parse_store_fix()
print(f"{datetime.datetime.now()} -> Prtl data sent to the DB")
@tasks.loop(hours=24)
async def publish_report(self):
self.index += 1
if self.index % 2:
scheme = "bi_warm"
else:
scheme = "bi_cold"
channel = bot.get_channel(REPORT_CHANNEL)
reports = generate_reports(scheme)
for report in reports:
message = '\n'.join(report)
await channel.send(message)
print(f"{datetime.datetime.now()} -> Report generated and sent")
if __name__ == "__main__":
intents = discord.Intents.default()
intents.message_content = True
bot = Bot(intents=intents)
bot.run(DISCORD_TOKEN)