Compare commits

..

No commits in common. "57502f3c9f902917bfff887b8d2e20808f2e496f" and "036200f1f737ca7d948e844eb54eabd3249c0b57" have entirely different histories.

3 changed files with 22 additions and 49 deletions

View File

@ -4,7 +4,7 @@ It's like Sopel, except rewritten from scratch using Twisted as a base and over
## Requirements
Python 3.6+
Python packages: `twisted, python-dateutil, requests, bs4, wolfram, pyenchant, emoji, Pillow, xml2dict, ipython, numpy, numpngw`
Python packages: `twisted, python-dateutil, requests, bs4, wolfram, pyenchant`
## Config
`nickname` - The nickname the bot will use.

View File

@ -1,23 +0,0 @@
#!/usr/bin/env python3
"""
Minecraft is a well-crafted program.
"""
import subprocess
import module
@module.require_admin
@module.commands('mc_start')
def minecraft_start_server(bot, trigger):
"""
Starts the minecraft server in case it crashes.
"""
cmd = ["tmux", "send", "-t", "main:2", "./start.sh", "ENTER"]
cmd_re = ["tmux", "send", "-t", "main:2", "^C", "ENTER"]
msg = "Start signal sent to the minecraft server."
if trigger.group(2) == "-r":
msg = "Re-" + msg
subprocess.run(cmd_re, check=True)
subprocess.run(cmd, check=True)
bot.msg(msg)

View File

@ -25,14 +25,13 @@ def setup(bot):
"api_url TEXT PRIMARY KEY,"
"name TEXT DEFAULT 'Anonymous',"
"last_post INTEGER,"
"time_since TEXT,"
"channel TEXT)")
"time_since TEXT)")
con.commit()
else:
for thread in watching:
if get_thread_url(thread[0]) in bot.memory["watcher"].keys():
continue
t = WatcherThread(bot, *thread)
t = WatcherThread(bot, thread[0], thread[1], thread[2], thread[3])
t.start()
bot.memory["watcher"][get_thread_url(thread[0])] = t
con.close()
@ -80,7 +79,7 @@ def get_thread_url(api_url):
@commands("watch")
@example(".watch https://boards.4chan.org/qst/thread/2 OPName")
@example(".watch https://boards.4chan.org/qst/thread/2")
def watch(bot, trigger):
"""
A thread watcher for 4chan.
@ -102,14 +101,12 @@ def watch(bot, trigger):
last_post = get_last_post(thread, name)
time_since = get_time()
t = WatcherThread(bot, api_url, name,last_post, time_since,trigger.channel)
t = WatcherThread(bot, api_url, name, last_post, time_since)
t.start()
bot.memory["watcher"][url] = t
bot.db.execute(
"INSERT INTO watcher(api_url, name, last_post, time_since, channel) "
"VALUES(?,?,?,?,?)",
(api_url, name, last_post, time_since, trigger.channel))
bot.db.execute("INSERT INTO watcher(api_url, name, last_post, time_since)"
" VALUES(?,?,?,?)", (api_url, name, last_post, time_since))
bot.msg("[\x0304Watcher\x03] Watching thread: \x0307" + url)
@ -139,13 +136,12 @@ def removeThread(bot, url):
class WatcherThread(threading.Thread):
def __init__(self, bot, api_url, name, last_post, time_since, channel):
def __init__(self, bot, api_url, name, last_post, time_since):
threading.Thread.__init__(self)
self.stop = threading.Event()
self.period = 20
self.bot = bot
self.channel = channel
self._bot = bot
self.api_url = api_url
self.name = name
self.last_post = last_post
@ -165,10 +161,10 @@ class WatcherThread(threading.Thread):
continue
if res.status_code == 404:
msg = "[\x0304Watcher\x03] Thread deleted: "
msg += f"\x0307{get_thread_url(self.api_url)}"
self.bot.msg(self.channel, msg)
removeThread(self.bot, self.api_url)
msg = "[\x0304Watcher\x03] Thread deleted: " \
+ f"\x0307{get_thread_url(self.api_url)}"
self._bot.msg(msg)
removeThread(self.bot, api_url)
self.stop.set()
continue
@ -177,18 +173,18 @@ class WatcherThread(threading.Thread):
thread = res.json()
if thread["posts"][0].get("closed"):
msg = "[\x0304Watcher\x03] Thread closed: "
msg += f"\x0307{get_thread_url(self.api_url)}"
self.bot.msg(self.channel, msg)
removeThread(self.bot, self.api_url)
msg = "[\x0304Watcher\x03] Thread closed: " \
+ f"\x0307{get_thread_url(self.api_url)}"
self._bot.msg(msg)
removeThread(self.bot, api_url)
self.stop.set()
continue
new_last_post = get_last_post(thread, self.name)
if new_last_post > self.last_post:
self.last_post = new_last_post
print(self.last_post)
msg = "[\x0304Watcher\x03] New post from \x0308"
msg += f"{self.name}\x03: \x0307{get_thread_url(self.api_url)}"
msg += f"#{self.last_post}"
self.bot.msg(self.channel, msg)
msg = "[\x0304Watcher\x03] New post from \x0308" \
+ f"{self.name}\x03: \x0307{get_thread_url(self.api_url)}"
+ f"#{self.last_post}"
self._bot.msg(msg)