Compare commits

...

3 Commits

Author SHA1 Message Date
57502f3c9f added command to start minecraft server 2019-01-17 11:19:12 -05:00
f9afc7bfe0 updated dependencies 2019-01-17 11:18:46 -05:00
2b56976c03 fixed watcher 2019-01-17 11:18:15 -05:00
3 changed files with 49 additions and 22 deletions

View File

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

23
modules/minecraft.py Executable file
View File

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