Skip to content
This repository was archived by the owner on Oct 25, 2021. It is now read-only.

Commit e29749e

Browse files
author
WindowsVistaisCool
committed
first revision
0 parents  commit e29749e

File tree

8 files changed

+666
-0
lines changed

8 files changed

+666
-0
lines changed

cogs/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .util import *

cogs/util.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import discord
2+
import json
3+
4+
def store(file, key=None, read=False, val=None, *, pop=False):
5+
with open(file, 'r') as v:
6+
x = json.load(v)
7+
if x is None: return
8+
if read is not False:
9+
if key is None:
10+
return x
11+
else:
12+
return x[key]
13+
elif pop is True:
14+
return
15+
else:
16+
if val is None:
17+
with open(file, 'w') as v:
18+
json.dump(key, v, indent=4)
19+
return
20+
x[key] = val
21+
with open(file, 'w') as v:
22+
json.dump(x, v, indent=4)
23+
24+
async def get_ready(bot):
25+
config = store('config.json', None, True)
26+
load_cogs(bot, config)
27+
await ready_status(bot, config)
28+
print("Ready")
29+
30+
def load_cogs(bot, config):
31+
for cog in config['cogs']:
32+
bot.load_extension(cog)
33+
34+
async def ready_status(client, x):
35+
f = x['testMode']
36+
def type():
37+
d = x['activity']
38+
if f:
39+
return discord.Game(name='Test mode (commands don\'t work)')
40+
elif x['atype'] == 'l':
41+
return discord.Activity(type=discord.ActivityType.listening, name=d)
42+
elif x['atype'] == 'w':
43+
return discord.Activity(type=discord.ActivityType.watching, name=d)
44+
elif x['atype'] == 'c':
45+
return discord.Activity(type=discord.ActivityType.competing, name=d)
46+
elif x['atype'] == 's':
47+
return discord.Streaming(name=d, url=x['surl'])
48+
else:
49+
return discord.Game(name=d)
50+
def stat():
51+
l = x['status']
52+
if l == 'dnd' or f:
53+
return discord.Status.dnd
54+
elif l == 'online':
55+
return discord.Status.online
56+
elif l == 'idle':
57+
return discord.Status.idle
58+
else:
59+
return discord.Status.invisible
60+
if x['atype'] != 'n' or f:
61+
await client.change_presence(status=stat(), activity=type())

config.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"token": "ODg2MjcwNjM5Nzg5NDY1NzIx.YTzJ2g.BVXEHgCyeDZUrQJ5OG3Hg7eA4fc",
3+
"pfx": "p/",
4+
"testMode": false,
5+
"status": "online",
6+
"atype": "w",
7+
"activity": "for updates",
8+
"owner_ids": [406629388059410434, 512063606750183429]
9+
}

latest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"message": "https://www.pccsk12.com/Home/Components/News/News/23909/"
3+
}

main.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import discord
2+
import requests
3+
import xmltodict
4+
from discord.ext import commands, tasks
5+
from discord_slash import SlashCommand
6+
from datetime import datetime
7+
from cogs.util import store, ready_status
8+
9+
config = store('config.json', None, True)
10+
client = commands.Bot(command_prefix=config['pfx'], help_command=None, owner_ids=config['owner_ids'])
11+
slash = SlashCommand(client, sync_commands=True, debug_guild=885634787119886337)
12+
13+
@slash.slash(name='join', description='Get an invite to the P-CEP discord')
14+
async def _join(ctx):
15+
await ctx.send("https://discord.gg/rHYsNSbxG7", hidden=True)
16+
17+
@client.event
18+
async def on_ready():
19+
await ready_status(client, config)
20+
pccs_feed.start()
21+
print("ready")
22+
23+
@client.event
24+
async def on_message(message):
25+
if message.author.bot: return
26+
await client.process_commands(message)
27+
28+
@client.command()
29+
@commands.is_owner()
30+
async def test(ctx):
31+
await pccs_feed()
32+
await ctx.message.delete()
33+
34+
@client.command()
35+
@commands.is_owner()
36+
async def start(ctx):
37+
pccs_feed.start()
38+
await ctx.send("started task loop")
39+
40+
@client.command()
41+
@commands.is_owner()
42+
async def stop(ctx):
43+
pccs_feed.start()
44+
await ctx.send("Stopped the task loop. Please note you must start it up again with `p/start`")
45+
46+
@tasks.loop(minutes=5)
47+
async def pccs_feed():
48+
raw = xmltodict.parse(requests.get("https://www.pccsk12.com/Home/Components/RssFeeds/RssFeed/View?ctID=5&cateIDs=23").text)
49+
data = raw['rss']['channel']['item']
50+
if f"{data[0]['link']}" == f"{store('latest.json', 'message', True)}":
51+
return
52+
else:
53+
if data[0]['description'] == None: data[0]['description'] = 'No description provided'
54+
embed = discord.Embed(title=data[0]['title'], description=data[0]['description'], timestamp=datetime.utcnow(), color=discord.Color.blurple(), url=data[0]['link'])
55+
embed.set_footer(text='Retrieved')
56+
embed.set_author(name="P-CEP News post")
57+
c = client.get_channel(886323743503298590)
58+
e = await c.send(content="<@&885280443044347915>", embed=embed)
59+
await e.publish()
60+
store('latest.json', 'message', val=data[0]['link'])
61+
62+
63+
client.run(config['token'])

react.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"a": "🇦",
3+
"b": "🇧",
4+
"c": "🇨",
5+
"d": "🇩",
6+
"e": "🇪",
7+
"f": "🇫",
8+
"g": "🇬",
9+
"h": "🇭",
10+
"i": "🇮",
11+
"j": "🇯",
12+
"k": "🇰",
13+
"l": "🇱",
14+
"m": "🇲",
15+
"n": "🇳",
16+
"o": "🇴",
17+
"p": "🇵",
18+
"q": "🇶",
19+
"r": "🇷",
20+
"s": "🇸",
21+
"t": "🇹",
22+
"u": "🇺",
23+
"v": "🇻",
24+
"w": "🇼",
25+
"x": "🇽",
26+
"y": "🇾",
27+
"z": "🇿"
28+
}

requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
discord
2+
discord-py-interactions
3+
requests
4+
xmltodict

0 commit comments

Comments
 (0)