🏡 index : ~doyle/dave.git

author Jordan Doyle <jordan@doyle.wf> 2017-07-22 20:26:32.0 +01:00:00
committer Jordan Doyle <jordan@doyle.wf> 2017-07-22 20:26:32.0 +01:00:00
commit
7a2abbac7665f4a45accf28142f01cc7404b6e08 [patch]
tree
05aa2cd325d53955a451594551b655fc84dce373
parent
9f7e5c047888d3e5be67e299e3bc7ab56e23a0fb
download
7a2abbac7665f4a45accf28142f01cc7404b6e08.tar.gz

defer module calls to threads



Diff

 dave/dave.py              | 9 +++++++--
 dave/modules/speedtest.py | 1 -
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/dave/dave.py b/dave/dave.py
index 0ed921a..f521f42 100644
--- a/dave/dave.py
+++ a/dave/dave.py
@@ -9,7 +9,8 @@
import re
import config
import datetime
from twisted.internet.threads import deferToThread
from twisted.internet import reactor
from twisted.internet.threads import deferToThreadPool


class Dave(irc.IRCClient):
@@ -75,12 +76,14 @@

        if method[1] is not None:
            # we matched a command
            method[1](self, method[2], nick, channel)
            deferToThreadPool(reactor, reactor.getThreadPool(), method[1], self,
                              method[2], nick, channel)

            if not (hasattr(method[1], "dont_always_run") and method[1].dont_always_run):
                for m in run:
                    # modules that should always be run regardless of priority
                    m[0](self, m[1], nick, channel)
                    deferToThreadPool(reactor, reactor.getThreadPool(), m[0], self,
                                      m[1], nick, channel)

    def irc_unknown(self, prefix, command, params):
        if command == "INVITE":
diff --git a/dave/modules/speedtest.py b/dave/modules/speedtest.py
index 912ebde..977c107 100644
--- a/dave/modules/speedtest.py
+++ a/dave/modules/speedtest.py
@@ -1,10 +1,9 @@
from requests import get
from bs4 import BeautifulSoup
import dave.module
from twisted.words.protocols.irc import assembleFormattedText, attributes as A

@dave.module.match(r'https?://(?:www\.|beta\.)?speedtest\.net/(?:my-)?result/([0-9]+)(?:.png)?')
@dave.module.priority(dave.module.Priority.HIGHEST)
@dave.module.dont_always_run_if_run()
def speedtest(bot, args, sender, source):
    res = get("http://www.speedtest.net/result/{}".format(args[0]), timeout=3)