working thing
parent
8f67a175ae
commit
6f0ad0de87
@ -1,51 +0,0 @@
|
||||
import os, json, random
|
||||
import urllib.parse
|
||||
import urllib
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import asyncio
|
||||
|
||||
from util_functions import *
|
||||
from global_config import configboi
|
||||
|
||||
# Fun internet things
|
||||
class Internet(commands.Cog):
|
||||
"""Useful tools on the interwebs"""
|
||||
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.confmgr = configboi("config.txt", False)
|
||||
|
||||
async def getasjson(self, url):
|
||||
try:
|
||||
data = await run_command_shell('curl "' + url + '"')
|
||||
return json.loads(data)
|
||||
except Exception as e:
|
||||
return '{"haha":"heeho"}'
|
||||
|
||||
@commands.command()
|
||||
async def kernel(self, ctx):
|
||||
"""Get Linux kernel info for host and latest"""
|
||||
try:
|
||||
await ctx.send(embed=infmsg("Kernel", "Getting kernel info."))
|
||||
data = await self.getasjson("https://www.kernel.org/releases.json")
|
||||
new_ver = data["latest_stable"]["version"]
|
||||
mine = await run_command_shell("uname -r")
|
||||
msg = (
|
||||
"I'm running: `"
|
||||
+ mine
|
||||
+ "`\nKernel.org reports stable is: `"
|
||||
+ new_ver
|
||||
+ "`"
|
||||
)
|
||||
await ctx.send(embed=infmsg("Kernel", msg))
|
||||
except Exception as e:
|
||||
await ctx.send(
|
||||
embed=errmsg("Kernel", "Had an issue getting info: `" + str(e) + "`")
|
||||
)
|
||||
syslog.log("Internet-Important", "Kernel command had error: " + str(e))
|
||||
|
||||
# End fun internet things
|
||||
def setup(bot):
|
||||
bot.add_cog(Internet(bot))
|
@ -0,0 +1,115 @@
|
||||
import sys, datetime, os
|
||||
|
||||
import discord
|
||||
from discord.ext import commands, tasks
|
||||
import feedparser,requests
|
||||
|
||||
from global_config import configboi
|
||||
|
||||
from util_functions import *
|
||||
|
||||
sc = configboi("config.txt", False)
|
||||
REFRESH_TIME = sc.getasint("REFRESH_TIME")
|
||||
|
||||
class RSS(commands.Cog):
|
||||
"""This cog handles RSS stuff"""
|
||||
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.confmgr = configboi("config.txt", False)
|
||||
|
||||
self.package_names = self.confmgr.getaslist("WATCHED_PACKAGES")
|
||||
temp = self.confmgr.getaslist("FEED_URLS")
|
||||
self.gitea_urls = self.confmgr.getaslist("GITEA_URLS")
|
||||
self.package_channel = self.confmgr.getasint("PACKAGE_CHANNEL")
|
||||
|
||||
|
||||
self.feed_urls = []
|
||||
for feed in temp:
|
||||
self.feed_urls.append("https://" + feed)
|
||||
|
||||
self.chan = self.bot.get_channel(self.package_channel)
|
||||
if self.chan is None:
|
||||
syslog.log("RSS", "Package task failed because we couldn't find the target channel.")
|
||||
sys.exit(1)
|
||||
|
||||
self.root = "package-cache"
|
||||
ensure(self.root)
|
||||
|
||||
self.package_task.start()
|
||||
|
||||
|
||||
def cog_unload(self):
|
||||
self.package_task.cancel()
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_ready(self):
|
||||
syslog.log("RSS", "Running initial package check")
|
||||
await self.check_packages()
|
||||
|
||||
@tasks.loop(seconds=REFRESH_TIME)
|
||||
async def package_task(self):
|
||||
await self.check_packages()
|
||||
|
||||
@package_task.before_loop
|
||||
async def before_status_task(self):
|
||||
syslog.log(
|
||||
"RSS", "Waiting for bot to be ready before starting package task"
|
||||
)
|
||||
await self.bot.wait_until_ready()
|
||||
syslog.log("RSS", "Bot is ready. Enabling package task")
|
||||
|
||||
async def sendwarn(self, msg):
|
||||
await self.chan.send(embed=warnmsg("RSS",msg))
|
||||
|
||||
async def senderr(self, msg):
|
||||
await self.chan.send(embed=errmsg("RSS",msg))
|
||||
|
||||
async def send(self, msg):
|
||||
await self.chan.send(embed=infmsg("RSS",msg))
|
||||
|
||||
def dolog(self, msg):
|
||||
syslog.log("RSS", msg)
|
||||
|
||||
async def check_packages(self):
|
||||
try:
|
||||
for feed in self.feed_urls:
|
||||
self.dolog("Checking: " + feed)
|
||||
previous = ""
|
||||
if check(self.root + "/" + feed.replace("/","-")):
|
||||
self.dolog("Found previous cached data")
|
||||
previous = open(self.root + "/" + feed.replace("/","-")).read().strip()
|
||||
else:
|
||||
self.dolog("No previous data")
|
||||
|
||||
new = requests.get(feed).text
|
||||
|
||||
if new != previous:
|
||||
self.dolog("New data is different")
|
||||
if check(self.root + "/" + feed.replace("/","-")):
|
||||
os.remove(self.root + "/" + feed.replace("/","-"))
|
||||
with open(self.root + "/" + feed.replace("/","-"), "w") as f:
|
||||
f.write(new)
|
||||
self.dolog("Updated cache")
|
||||
|
||||
d = feedparser.parse(new)
|
||||
hadNew = False
|
||||
|
||||
for item in d.entries:
|
||||
for tgt in self.package_names:
|
||||
if tgt in str(item['title']):
|
||||
await self.send("Package change: `" + str(item['title']) + "`")
|
||||
hadNew = True
|
||||
break
|
||||
|
||||
if not hadNew:
|
||||
await self.send("No package changes to report :)")
|
||||
|
||||
else:
|
||||
await self.send("No package changes to report :)")
|
||||
except Exception as e:
|
||||
syslog.log("RSS ERROR", str(e))
|
||||
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(RSS(bot))
|
@ -1,4 +1,6 @@
|
||||
py-cord[voice]
|
||||
discord-pretty-help
|
||||
requests
|
||||
asyncio
|
||||
asyncio
|
||||
requests
|
||||
feedparser
|
Loading…
Reference in New Issue