예제 #1
0
 def __init__(self, dbconn):
     self.keyword = ("handle", "files", "links")
     self.response = PluginResponse()
     self.error = ""
     self.dbconn = dbconn
     self.opt = "files"
     print("Done loading")
예제 #2
0
        def command(self, args):
                response = PluginResponse()

                day_of_year = datetime.now().timetuple().tm_yday

                seaday = int(day_of_year % 73)
                season = self.seasons[int(day_of_year / 73)]
                day = self.days[int((day_of_year -1) % 5)]
                response.setText("Today is {}, day {}  of {} . Hail Eris, all Hail Discordia".format(day,seaday, season))
                

                return response
예제 #3
0
 def __init__(self, dbconn):
     self.keyword = ("jargon", )
     self.response = PluginResponse()
     self.jargonindex = list()
     self.jargonlower = dict()
     with open(storefile) as f:
         for line in f:
             j_entry = line.rstrip()
             if not (j_entry == ''):
                 self.jargonindex.append(j_entry)
                 for i in j_entry.split():
                     if i.lower() in self.jargonlower:
                         self.jargonlower[i.lower()].append(j_entry)
                     else:
                         self.jargonlower[i.lower()] = [
                             j_entry,
                         ]
     self.jarlength = len(self.jargonindex)
예제 #4
0
    def command(self, args):
        text = args.text
        response = PluginResponse()
        print(text)

        response.setText("The usual place")

        try:

            if (text != ''):

                resp = self.parse_command(text)
                response.setText(resp)

            else:
                response.setText(self.choose_lunch())
        except:

            e = sys.exc_info()[0]
            response.setText("NFI {}".format(e))
        return response
예제 #5
0
class store(Plugin):
    def __init__(self, dbconn):
        self.keyword = ("store", )
        self.response = PluginResponse()
        self.error = ""
        self.dbconn = dbconn

    def command(self, args):
        self.response.setText("Nope")
        text = args.text.split()
        userID = args.user["user"]["id"]
        tag = "generic"

        if (len(text) > 1):
            tag = text[-1]
            stored = " ".join(text[:-1])
        else:
            stored = text[0]
        try:
            # replace with function
            self.error = self.dbconn.query(
                """INSERT INTO `store`(`text`, `tag`, `userID`) VALUES(%s, %s, %s)""",
                (stored, tag, userID))
            self.response.setText("Added for {}!".format(
                args.user["user"]["name"]))
        except:
            self.response.setText("Cannot la: {}".format(self.error))

        return self.response
예제 #6
0
class fetchurl(Plugin):
        def __init__(self, dbconn):
                self.keyword = ("fetchurl",)
                self.response = PluginResponse()

        def command(self, args):
                text = args.text
                self.response.setText("Nope")
                url = text[0]
                resp = requests.get(url)
                if (resp.status_code == 200):
                        txt = html2text.html2text(resp.text).split("\n")
                        txt = txt[6:-6]
                        if (len(txt) > 15):
                                txt = txt[:15]
                        
                                txt[-1] += "\n(more ...)\n "
                        
                                
                        txt.append("\n" + url)

                        txt = "\n".join(txt)
                        self.response.setText(txt)
                                
                else:

                        self.response.setText("I couldn't find that url!")
                return self.response
예제 #7
0
class known(Plugin):
    def __init__(self, dbconn):
        self.keyword = ("known", )
        self.response = PluginResponse()
        self.error = ""
        self.dbconn = dbconn

    def command(self, args):
        self.response.setText("Nope")

        text = args.text.split(" ")
        #userID = args.user["user"]["id"]

        #if (text[0] == "update"):

        try:

            users = self.dbconn.query("SELECT `title`, `name` FROM `users`",
                                      [])
            resp = "TISM know the following people obey the TED commandments: \n"
            #print(users)
            for user in users:
                if (user[0]):
                    resp += "{} ".format(user[0])
                resp += "{} \n".format(user[1])
            self.response.setText(resp)
        except:
            self.response.setText("Cannot la: {}".format(self.error))

        return self.response
예제 #8
0
class store(Plugin):
    def __init__(self, dbconn):
        self.keyword = ("handle", "files", "links")
        self.response = PluginResponse()
        self.error = ""
        self.dbconn = dbconn
        self.opt = "files"
        print("Done loading")

    def command(self, args):
        self.response.setText("Nope")
        text = args.text.split()
        userID = args.user["user"]["id"]
        if args.command == "handle":
            if (args.opt == 0):
                self.response.setText("\n\nOpted out - not storing\n\n")
                return self.response
            tag = text[0]
            url = text[1]
            fileID = text[-1]
            stored = url

            if (tag == 'file_share'):
                try:
                    resp = requests.get(url,
                                        headers={
                                            "Authorization":
                                            "Bearer {}".format(
                                                os.environ["BOT_TOKEN"])
                                        },
                                        stream=True)
                    resp.raise_for_status()

                    if resp.ok:
                        filedir = "files/" + userID + "/"
                        if not os.path.exists(filedir):
                            os.makedirs(filedir)
                        with open(filedir + fileID, 'wb') as f:
                            for block in resp.iter_content(1024):
                                f.write(block)
                            f.close()

                except Exception as e:
                    self.response.setText("No response! {}".format(e))

            try:
                # replace with function
                self.error = self.dbconn.query(
                    """INSERT INTO `store`(`text`, `tag`, `userID`) VALUES(%s, %s, %s)""",
                    (stored, tag, userID))
                self.response.setText("Added for {}!".format(
                    args.user["user"]["name"]))
            except:
                self.response.setText("Cannot la: {}".format(self.error))

        elif args.command == "files":
            self.error = self.dbconn.query(
                """SELECT text from `store` WHERE userID = %s AND `tag`=%s""",
                (userID, "file_share"))
            resp = ""
            for myfile in self.error:
                resp += myfile[0] + "\n"
            self.response.setText(resp)
        elif args.command == "links":
            self.error = self.dbconn.query(
                """SELECT text from `store` WHERE userID = %s AND`tag`=%s""",
                (userID, "generic"))
            resp = ""
            for myfile in self.error:
                resp += " {} \n".format(myfile[0])
            self.response.setText(resp)

        return self.response
예제 #9
0
 def __init__(self, dbconn):
     self.keyword = ("store", )
     self.response = PluginResponse()
     self.error = ""
     self.dbconn = dbconn
예제 #10
0
 def __init__(self, dbconn):
         self.keyword = ("fetchurl",)
         self.response = PluginResponse()
예제 #11
0
class jargon(Plugin):
    myhelp = """Usage: !jargon <term>. Goes and looks up the internet Jargon File for a definition of <term>"""

    def __init__(self, dbconn):
        self.keyword = ("jargon", )
        self.response = PluginResponse()
        self.jargonindex = list()
        self.jargonlower = dict()
        with open(storefile) as f:
            for line in f:
                j_entry = line.rstrip()
                if not (j_entry == ''):
                    self.jargonindex.append(j_entry)
                    for i in j_entry.split():
                        if i.lower() in self.jargonlower:
                            self.jargonlower[i.lower()].append(j_entry)
                        else:
                            self.jargonlower[i.lower()] = [
                                j_entry,
                            ]
        self.jarlength = len(self.jargonindex)

    def build_url(self, searchstr):
        searchstr = "-".join(searchstr.split())
        cap = searchstr[0]
        return "http://www.catb.org/jargon/html/{}/{}.html".format(
            cap.upper(), searchstr)

    def build_alt_list(self, searchstr):
        results = list()
        for mystr in searchstr.split():
            resp = self.jargonlower.get(mystr.lower(), "")
            if resp != "":
                for alt in resp:
                    results.append(self.build_url(alt))
        return results

    def command(self, args):
        text = args.text
        self.response.setText("Nope")
        searchstr = self.jargonindex[random.randint(0, self.jarlength)]

        if (text != ''):
            searchstr = text

        url = self.build_url(searchstr)
        resp = requests.get(url)
        if (resp.status_code == 200):
            txt = html2text.html2text(resp.text).split("\n")
            ftxt = ''

            txt = txt[6:-6]
            if (len(txt) > MAXLINES):
                txt = txt[:MAXLINES]

                txt[-1] += "\n(more ...)\n "

            for i in (txt):
                if (i.strip() != ''):
                    ftxt += i.strip() + "\n"

            ftxt += ("\n" + url)
            self.response.setText(ftxt)

        elif (resp.status_code == 404):
            alt_list = self.build_alt_list(text)
            resp = " No entry for {0} ".format(url)
            if len(alt_list) > 0:
                for alt in alt_list:
                    resp += "\n Did you mean {} ?".format(alt)

            self.response.setText(resp)

        else:

            self.response.setText(
                "I couldn't find that url! {0} ({1}) ".format(
                    url, resp.status_code))
        return self.response
예제 #12
0
class lyrics(Plugin):
    myhelp = """Usage: !lyrics <songname>. Goes and looks up the AZLyrics db for lyrics to the song """

    def __init__(self, dbconn):
        self.keyword = ("lyrics", )
        self.response = PluginResponse()

    def build_url(self, searchstr):
        return (
            "https://search.azlyrics.com/search.php?q={}".format(searchstr))

    def command(self, args):
        text = args.text

        try:
            if (text != ' '):
                searchstr = "+".join(text.split())
                print(searchstr)
                url = self.build_url(searchstr)
                print(url)
                resp = requests.get(url)
                print(resp)
                if (resp.status_code == 200):
                    txtcount = 0
                    txt = ""
                    soup = BeautifulSoup(resp.text, 'html.parser')
                    link = soup.find_all('td',
                                         class_="text-left visitedlyr")[0]
                    print("Link:{}".format(link))
                    url = link.find_all('a')[0].get("href")
                    print("URL:{}".format(url))
                    resp = requests.get(url)
                    print("Resp:{}".format(resp))
                    print("=================================")
                    if (resp.status_code == 200):
                        soup = BeautifulSoup(resp.text, 'html.parser')
                        #print("Response: {}".format(resp.text))
                        txt = soup.find_all('div', class_="")[0].contents
                        print("Lyrics: {}".format(txt))
                        ftxt = ''
                        for ln in txt[2:]:
                            try:
                                ftxt += html2text.html2text(ln).strip() + "\n"
                            except:
                                ftxt += ""

                            #if (txtcount < MAXLINES):
                            #txt += "{}".format(link)
                            #txtcount += 1
                            #else:
                            #txt += "More: {}".format(url)
                            #txtcount += 1
                            #break
                        print(ftxt)
                        self.response.setText(ftxt)
                else:
                    self.response.setText("Not found")

            else:
                self.response.setText(myhelp)
        except:
            e = sys.exc_info()[0]
            print("nope {}".format(e))
            self.response.setText("NFI {}".format(e))
        return self.response
예제 #13
0
 def __init__(self, dbconn):
     self.keyword = ("lyrics", )
     self.response = PluginResponse()
예제 #14
0
 def command(self, args):
         response = PluginResponse()
         response.setText("Why don't you go f**k yourself")
         return response