working thing

pull/1/head
Matt C 3 years ago
parent 8f67a175ae
commit 6f0ad0de87

1
.gitignore vendored

@ -1,6 +1,7 @@
# Custom # Custom
system_log.txt* system_log.txt*
.cavetoken .cavetoken
package-cache/
# ---> Python # ---> Python
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files

@ -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))

@ -22,6 +22,7 @@ class Status(commands.Cog):
def cog_unload(self): def cog_unload(self):
self.status_task.cancel() self.status_task.cancel()
self.uptime_logger.cancel()
async def setDefaultStatus(self): async def setDefaultStatus(self):
ac_type = None ac_type = None

@ -8,12 +8,12 @@
# General bot stuff # General bot stuff
# Types: watching, listening, playing # Types: watching, listening, playing
DEFAULT_STATUS_TYPE:playing DEFAULT_STATUS_TYPE:watching
# These are currently the only substitutions # These are currently the only substitutions
# - {number_users} # - {number_users}
# - {guild_count} # - {guild_count}
DEFAULT_STATUS_TEXT:ooga booga w/ {number_users} friends DEFAULT_STATUS_TEXT:for ;
# Any default cogs you don't want to load: # Any default cogs you don't want to load:
# Example: UNLOAD_COGS:Internet,Speak # Example: UNLOAD_COGS:Internet,Speak
@ -28,11 +28,24 @@ OWNER:117445905572954121
# Note {command} is the only substitution allowed here (we do auto-mention the user) # Note {command} is the only substitution allowed here (we do auto-mention the user)
WRONG_PERMS:You're not a special snowflake, so you can't run `{command}` WRONG_PERMS:You're not a special snowflake, so you can't run `{command}`
# {username} is the only one here
NEW_MEMBER:Welcome, {username}
# and {channel} is the only one here
INTRO_CHANNEL:You should go to {channel}, since it's your first time here.
# Should the owner get a DM when the bot restarts # Should the owner get a DM when the bot restarts
OWNER_DM_RESTART:True OWNER_DM_RESTART:True
######################################################################################
# Package settings #
######################################################################################
# Package names to care about
WATCHED_PACKAGES:grub,arch-install-scripts,base,filesystem,lsb-release,neofetch,pfetch
# How often to re-query the feed(s) {in seconds}
REFRESH_TIME:3600
# Feed source(s)
FEED_URLS:archlinux.org/feeds/packages/
# Crystal URL(s)
GITEA_URLS:https://git.getcryst.al/crystal/packages-any,https://git.getcryst.al/crystal/packages-x86_64
# Channel to send notifications
PACKAGE_CHANNEL:900844916974977125

@ -2,3 +2,5 @@ py-cord[voice]
discord-pretty-help discord-pretty-help
requests requests
asyncio asyncio
requests
feedparser
Loading…
Cancel
Save