Compare commits
3 Commits
036200f1f7
...
57502f3c9f
Author | SHA1 | Date | |
---|---|---|---|
57502f3c9f | |||
f9afc7bfe0 | |||
2b56976c03 |
|
@ -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`
|
||||
Python packages: `twisted, python-dateutil, requests, bs4, wolfram, pyenchant, emoji, Pillow, xml2dict, ipython, numpy, numpngw`
|
||||
|
||||
## Config
|
||||
`nickname` - The nickname the bot will use.
|
||||
|
|
23
modules/minecraft.py
Executable file
23
modules/minecraft.py
Executable 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)
|
|
@ -25,13 +25,14 @@ def setup(bot):
|
|||
"api_url TEXT PRIMARY KEY,"
|
||||
"name TEXT DEFAULT 'Anonymous',"
|
||||
"last_post INTEGER,"
|
||||
"time_since TEXT)")
|
||||
"time_since TEXT,"
|
||||
"channel TEXT)")
|
||||
con.commit()
|
||||
else:
|
||||
for thread in watching:
|
||||
if get_thread_url(thread[0]) in bot.memory["watcher"].keys():
|
||||
continue
|
||||
t = WatcherThread(bot, thread[0], thread[1], thread[2], thread[3])
|
||||
t = WatcherThread(bot, *thread)
|
||||
t.start()
|
||||
bot.memory["watcher"][get_thread_url(thread[0])] = t
|
||||
con.close()
|
||||
|
@ -79,7 +80,7 @@ def get_thread_url(api_url):
|
|||
|
||||
|
||||
@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):
|
||||
"""
|
||||
A thread watcher for 4chan.
|
||||
|
@ -101,12 +102,14 @@ 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)
|
||||
t = WatcherThread(bot, api_url, name,last_post, time_since,trigger.channel)
|
||||
t.start()
|
||||
bot.memory["watcher"][url] = t
|
||||
|
||||
bot.db.execute("INSERT INTO watcher(api_url, name, last_post, time_since)"
|
||||
" VALUES(?,?,?,?)", (api_url, name, last_post, time_since))
|
||||
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.msg("[\x0304Watcher\x03] Watching thread: \x0307" + url)
|
||||
|
||||
|
@ -136,12 +139,13 @@ def removeThread(bot, url):
|
|||
|
||||
|
||||
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)
|
||||
self.stop = threading.Event()
|
||||
self.period = 20
|
||||
|
||||
self._bot = bot
|
||||
self.bot = bot
|
||||
self.channel = channel
|
||||
self.api_url = api_url
|
||||
self.name = name
|
||||
self.last_post = last_post
|
||||
|
@ -161,10 +165,10 @@ class WatcherThread(threading.Thread):
|
|||
continue
|
||||
|
||||
if res.status_code == 404:
|
||||
msg = "[\x0304Watcher\x03] Thread deleted: " \
|
||||
+ f"\x0307{get_thread_url(self.api_url)}"
|
||||
self._bot.msg(msg)
|
||||
removeThread(self.bot, api_url)
|
||||
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)
|
||||
self.stop.set()
|
||||
continue
|
||||
|
||||
|
@ -173,18 +177,18 @@ class WatcherThread(threading.Thread):
|
|||
|
||||
thread = res.json()
|
||||
if thread["posts"][0].get("closed"):
|
||||
msg = "[\x0304Watcher\x03] Thread closed: " \
|
||||
+ f"\x0307{get_thread_url(self.api_url)}"
|
||||
self._bot.msg(msg)
|
||||
removeThread(self.bot, api_url)
|
||||
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)
|
||||
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
|
||||
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)
|
||||
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user