示例#1
0
    def y(status):
        content = conv.text(status["content"])
        account = status["account"]
        if count.y == True:
            if re.compile("こおり.*ねじりサーチ.*[OoOo][FfFf][FfFf]").search(
                    status['content']):
                if account["acct"] == "y" or account["acct"] == "0":
                    count.y = False
                    return toot.toot_res("ねじりサーチ、終了しました。", sec=3)
            elif re.compile("ねじりわさび|ねじり|わさび|ねじわさ|[Kk]nzk[Aa]pp|神崎丼アプリ")\
                    .search(status['content']):  # 抜き出し
                if account["acct"] is not "y" or account[
                        "acct"] is not "1":  # 自分とねじりわさびさんを感知しないように
                    yuzu = re.search(
                        "(ねじりわさび|ねじり|わさび|ねじわさ|[Kk]nzk[Aa]pp|神崎丼アプリ)", content)
                    post = ("@y {}を感知しました。").format(str(yuzu.group(1)))
                    return toot.toot(mastodon, post, "direct", status["id"],
                                     None, None)

        else:
            if account["acct"] == "y" or account["acct"] == "0":
                if re.compile("こおり.*ねじりサーチ.*[OoOo][NnNn]").search(
                        status['content']):
                    count.y = True
                    return toot.toot_res("ねじりサーチ、スタートです!", sec=3)
示例#2
0
 def res03(status):  # 該当する文字があるとメディアをアップロードしてトゥートしてくれます。
     content = conv.text(status["content"])
     with codecs.open('bot\\reply_media.csv', 'r', "UTF-8", "ignore") as f:
         for row in csv.reader(f):
             if re.compile(row[2]).search(re.sub("<p>|</p>", "", content)):
                 print("◇Hit")
                 l = []
                 with codecs.open('bot\\res\\' + row[1] + '.txt', 'r',
                                  'utf-8') as f:
                     for x in f:
                         l.append(
                             x.rstrip("\r\n|\ufeff").replace('\\n', '\n'))
                 m = len(l)
                 s = random.randint(1, m)
                 post = l[s - 1]
                 with codecs.open('bot\\res_med\\' + row[3] + '.txt', 'r',
                                  'utf-8') as f:
                     j = []
                     for x in f:
                         j.append(x.rstrip("\r\n").replace('\\n', '\n'))
                 xxx = re.sub("(.*)\.", "", j[s - 1])
                 media_files = [
                     mastodon.media_post("bot\\media\\" + j[s - 1])
                 ]
                 print("◇メディア選択しました")
                 print(j[s - 1])
                 toot.toot_res(mastodon, post, "public", None, media_files,
                               None, int(row[0]))
                 return
示例#3
0
 def res05(status):
     content = conv.text(status["content"])
     if re.compile("こおり(.*)\d+[dD]\d+").search(content):
         print("○hitしました♪")
         account = status["account"]
         post = "@" + str(account["acct"]) + "\n" + game.dice(content)
         toot.toot_res(mastodon, post, status["visibility"], None, None,
                       "サイコロ振りますね。", 3)
示例#4
0
 def res02(status):  # 該当するセリフからランダムtootが選ばれてトゥートします。
     content = conv.text(status["content"])
     with codecs.open('bot\\reply_random.csv', 'r', "UTF-8", "ignore") as f:
         for row in csv.reader(f):
             if re.compile(row[2]).search(re.sub("<p>|</p>", "", content)):
                 print("◇Hit")
                 post = conv.rand_w('bot\\res\\' + row[1] + '.txt')
                 toot.toot_res(mastodon, post, "public", sec=int(row[0]))
                 return
示例#5
0
 def res01(status):  # お返事関数シンプル版。
     content = conv.text(status["content"])
     with codecs.open('bot\\reply.csv', 'r', "UTF-8", "ignore") as f:
         for row in csv.reader(f):
             if re.compile(row[2]).search(content):
                 print("◇Hit")
                 post = row[1].replace('\\n', '\n')
                 toot.toot_res(
                     mastodon,
                     post,
                     "public",
                 )
示例#6
0
    def on_notification(self, notification):  # 通知を監視します。
        try:
            print(("===●user_on_notification【{}】●===").format(
                str(notification["type"])))
            account = notification["account"]
            if notification["type"] == "follow":  # 通知がフォローだった場合はフォロバします。
                print(account["display_name"])
                sleep(2)
                mastodon.account_follow(account["id"])
                print("◇フォローを返しました。")

            elif notification["type"] == "mention":  # 通知がリプだった場合です。
                status = notification["status"]
                log = threading.Thread(Log(status).read())
                log.run()
                if account["acct"] != "1":
                    men.mention(status)

            elif notification["type"] == "favourite":  # 通知がベルのときです。
                status = notification["status"]
                print("{0} @{1} さんがベルを鳴らしました。".format(account["display_name"],
                                                      account["acct"]))
                if account["acct"] == "Knzk":
                    count.knzk_fav += 1
                    print("神崎にふぁぼられた数:" + str(count.knzk_fav))
                    if count.knzk_fav == 100:
                        f = codecs.open('bot\\bot\\res\\fav_knzk.txt', 'r',
                                        'utf-8')
                        l = []
                        for x in f:
                            l.append(x.rstrip("\r\n").replace('\\n', '\n'))
                        f.close()
                        m = len(l)
                        s = random.randint(1, m)
                        post = (l[s - 1])
                        g_vis = "public"
                        toot.toot_res(mastodon, post, g_vis)
                        count.knzk_fav = 0

            elif notification["type"] == "reblog":  # 通知がブーストのときです。
                print("{0} @{1} さんがブーストしました。".format(account["display_name"],
                                                     account["acct"]))
        except IncompleteRead:
            print("【USER】接続が切れました。")
            pass
        except Exception as e:
            e_me()
            pass
        except:
            pass
        print("   ")
        pass
示例#7
0
 def adana(status):
     account = status["account"]
     content = conv.text(status["content"])
     if re.compile("こおり.*あだ名「(.+)」って呼んで").search(content):
         print("○hitしました♪")
         ad = re.search("こおり.*あだ名「(.+)」って呼んで", content)
         adan = ad.group(1)
         with codecs.open(
                 'data\\dic_time\\adana\\' + account["acct"] + '.txt', 'w',
                 'UTF-8') as f:
             f.write(adan)
         post = "分かりました。\n次からは「{}」ってお呼びしますね。".format(adan)
         toot.toot_res(mastodon, post, status["visibility"], sec=4)
示例#8
0
 def omikuji(status):
     account = status["account"]
     content = conv.text(status["content"])
     koori = ('こおり(.*)みくじ(.*)(おねが(.*)い|お願(.*)い|[引ひ]([きく]|いて)|'
              'や[りる]|ください|ちょうだい|(宜|よろ)しく|ひとつ|し(て|たい))')
     if re.compile(koori).search(content):
         if account['acct'] != "1":
             post = omikuji(status)
             if post:
                 return toot.toot_res(mastodon, post, "public", sec=6)
示例#9
0
 def check03(status):  # お休みする人を記憶
     account = status["account"]
     content = conv.text(status["content"])
     try:
         with codecs.open(
                 'data\\dic_time\\adana\\' + account["acct"] + '.txt', 'r',
                 'UTF-8') as f:
             display_name = f.read()
     except:
         if account['display_name'] == "":
             display_name = account['acct'] + "さん"
         else:
             display_name = re.sub("@[a-zA-Z0-9]+|\s", "",
                                   account['display_name']) + "さん"
     if account["acct"] != "1":  # 一人遊びで挨拶しないようにっするための処置
         if re.compile("[寝ね](ます|る|マス)([よかぞね…。うぅー~!]*)$|"
                       "[寝ね](ます|る|マス)(.*)[ぽお]や[すし]").search(content):
             print("◇Hit")
             post = display_name + "、" + conv.rand_w('bot\\time\\oya.txt')
             toot.toot_res(mastodon, post, "public", sec=5)
             with codecs.open('data\\oyasumi\\' + account["acct"] + '.txt',
                              'w', 'UTF-8') as f:
                 f.write("good_night")
             try:
                 with codecs.open(
                         'data\\dic_time\\' + account["acct"] + '.json',
                         'r', 'UTF-8') as f:
                     zzz = {}
                     zzz = json.load(f)
             except:
                 zzz = {}
             with codecs.open(
                     'data\\dic_time\\' + account["acct"] + '.json', 'w',
                     'UTF-8') as f:
                 zzz.update({"sleep": str(status["created_at"])})
                 json.dump(zzz, f)
             print("◇寝る人を記憶しました")
示例#10
0
 def check00(status):
     account = status["account"]
     ct = account["statuses_count"]
     if account["acct"] == "1":
         ct += 1
         if re.match('^\d+000$', str(ct)):
             post = str(ct) + 'toot、達成しました……!\n#こおりキリ番記念'
             g_vis = "public"
             toot.toot_res(mastodon, post, "public", sec=5)
     else:
         if re.match('^\d+0000$', str(ct)):
             post = "@" + account['acct'] + "\n" + str(
                 ct) + 'toot、おめでとうございます!'
             g_vis = "public"
             toot.toot_res(mastodon, post, "public", sec=5)
         elif re.match('^\d000$', str(ct)):
             post = "@" + account['acct'] + "\n" + str(
                 ct) + 'toot、おめでとうございます。'
             g_vis = "public"
             toot.toot_res(mastodon, post, "public", sec=5)
示例#11
0
    def res04(status):  # こおりちゃん式挨拶機能の実装
        account = status["account"]
        content = re.sub("<p>|</p>", "", str(status['content']))
        xxx = "[((].+[))]|@[a-zA-Z0-9_]+|\s|@.+|:"
        try:
            with codecs.open(
                    'data\\dic_time\\adana\\' + account["acct"] + '.txt', 'r',
                    'UTF-8') as f:
                display_name = f.read()
            if re.compile("^[ -/ -】:-\?\[-`\{-~]+$").search(display_name):
                if account['display_name'] == "":
                    display_name = account['acct'] + "さん"
                else:
                    display_name = re.sub(xxx, "",
                                          account['display_name']) + "さん"
            elif display_name == "":
                if account['display_name'] == "":
                    display_name = account['acct'] + "さん"
                else:
                    display_name = re.sub(xxx, "",
                                          account['display_name']) + "さん"
        except:
            if account['display_name'] == "":
                display_name = account['acct'] + "さん"
            else:
                display_name = re.sub(xxx, "", account['display_name']) + "さん"
        try:
            if account["acct"] != "1":  # 一人遊びで挨拶しないようにするための処置
                try:
                    with codecs.open(
                            'data\\oyasumi\\' + account["acct"] + '.txt', 'r',
                            'UTF-8') as f:
                        zzz = f.read()
                except:
                    print("◇初めての人に会いました。")
                    post = display_name + "\n" + "はじめまして、よろしくお願いいたします。"
                    g_vis = "public"
                    toot.toot_res(mastodon, post, "public", sec=5)
                    with codecs.open(
                            'data\\oyasumi\\' + account["acct"] + '.txt', 'w',
                            'UTF-8') as f:
                        f.write("active")
                    zzz = ""
                if zzz == "good_night":
                    koori = "まだ(寝|起|ねない|おきてる)|寝るのはまだ|寝(ない|ません)|起きてる"
                    if re.compile(koori).search(content):
                        print("◇Hit")
                        post = display_name + "、まだ起きてるんですね。了解です。"
                        toot.toot_res(mastodon, post, "public", sec=5)
                        with codecs.open(
                                'data\\oyasumi\\' + account["acct"] + '.txt',
                                'w', 'UTF-8') as f:
                            f.write("active")
                    else:
                        try:
                            with codecs.open(
                                    'data\\dic_time\\' + account["acct"] +
                                    '.json', 'r', 'UTF-8') as f:
                                nstr = json.load(f)
                            last_time = conv.delta(nstr["sleep"])
                            now_time = status['created_at']
                            last_time = last_time.replace(
                                tzinfo=tz.tzutc()).astimezone(JST)
                            now_time = now_time.replace(
                                tzinfo=tz.tzutc()).astimezone(JST)
                            delta = now_time - last_time
                            if delta.total_seconds() < 600:
                                pass
                            elif delta.total_seconds() >= 3600:
                                print("◇Hit")
                                post = display_name + "、" + conv.rand_w(
                                    'bot\\time\\oha.txt')
                                toot.toot_res(mastodon, post, "public", sec=5)
                                with codecs.open(
                                        'data\\oyasumi\\' + account["acct"] +
                                        '.txt', 'w', 'UTF-8') as f:
                                    f.write("active")
                                return
                            elif delta.total_seconds() >= 600:
                                print("◇Hit")
                                post = display_name + "、" + conv.rand_w(
                                    'bot\\time\\mada.txt')
                                toot.toot_res(mastodon, post, "public", sec=5)
                                with codecs.open(
                                        'data\\oyasumi\\' + account["acct"] +
                                        '.txt', 'w', 'UTF-8') as f:
                                    f.write("active")
                                return
                        except:
                            print("◇Hit_エラー回避")
                            post = display_name + "、" + conv.rand_w(
                                'bot\\time\\oha.txt')
                            g_vis = "public"
                            toot.toot_res(mastodon, post, "public", sec=5)
                            with codecs.open(
                                    'data\\oyasumi\\' + account["acct"] +
                                    '.txt', 'w', 'UTF-8') as f:
                                f.write("active")

                elif zzz == "active":
                    with open('data\\at_time\\' + account["acct"] + '.txt',
                              'r') as f:
                        last_time = f.read()
                    last_time = conv.delta(last_time)
                    now_time = status[
                        'created_at']  # \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{6}+00:00
                    last_time = last_time.replace(
                        tzinfo=tz.tzutc()).astimezone(JST)
                    now_time = now_time.replace(
                        tzinfo=tz.tzutc()).astimezone(JST)
                    delta = now_time - last_time
                    if delta.total_seconds() >= 604800:
                        to_r = conv.rand_w('bot\\time\\ohisa.txt')
                        print("◇Hit")
                        post = display_name + "\n" + to_r
                        return toot.toot_res(mastodon, post, "public", sec=5)
                    elif delta.total_seconds() >= 75600:
                        if now_time.hour in range(4, 12):
                            to_r = conv.rand_w('bot\\time\\oha.txt')
                        elif now_time.hour in range(12, 20):
                            to_r = conv.rand_w('bot\\time\\kon.txt')
                        else:
                            to_r = conv.rand_w('bot\\time\\kob.txt')
                        print("◇Hit")
                        post = display_name + "、" + to_r
                        return toot.toot_res(mastodon, post, "public", sec=5)
                    elif delta.total_seconds() >= 28800:
                        to_r = conv.rand_w('bot\\time\\hallo.txt')
                        print("◇Hit")
                        post = display_name + "、" + to_r
                        return toot.toot_res(mastodon, post, "public", sec=5)
        except:
            print("◇失敗しました。")
            with codecs.open('data\\oyasumi\\' + account["acct"] + '.txt', 'w',
                             'UTF-8') as f:
                f.write("active")
            e_me()
示例#12
0
def omikuji(status):
    try:
        account = status['account']
        with open('data\\dic_time\\' + account["acct"] + '.json', 'r') as f:
            if not f == "":
                nstr = json.load(f)
        last_time = datetime.strptime(
            re.sub(" ..:..:...*", "",
                   str(conv.delta(str(nstr["omikuji_time"])))), '%Y-%m-%d')
        now_time = datetime.strptime(
            re.sub(" ..:..:...*", "",
                   str(conv.delta(str(status['created_at'])))), '%Y-%m-%d')
        if last_time != now_time:
            print("◇Hit_try")
            post = conv.rand_w('bot\\game\\' + 'kuji' + '.txt'
                               ) + " " + "@" + account['acct'] + " #こおりみくじ"
            c = {}
            c.update({"omikuji_time": str(status["created_at"])})
            w = nstr["omikuji_lack"]
            n1 = order(w)
            z = re.search("【(.+)】", post)
            c.update({"omikuji_lack": z.group(1)})
            n2 = order(z.group(1))
            if n2 == 6:
                post = post + "\n大吉です、おめでとうございます。"
            elif n2 == -5:
                post = post + "\n……ご愁傷様です。元気だしてくださいね。"
            elif n1 < n2:
                post = post + "\n前回より運気が上がりましたね。"
            elif n1 > n2:
                post = post + "\n前回より運気が下がりましたね。"
            elif n1 == n2:
                post = post + "\n前回と同じ結果になりましたね。"
            with codecs.open('data\\dic_time\\' + account["acct"] + '.json',
                             'w+', 'UTF-8') as f:
                json.dump(c, f)
            with codecs.open(
                    'data\\dic_time\\omikuji_diary\\' + account["acct"] +
                    '.json', 'r', 'UTF-8') as f:
                a = {}
                a = json.load(f)
            with codecs.open(
                    'data\\dic_time\\omikuji_diary\\' + account["acct"] +
                    '.json', 'w', 'UTF-8') as f:
                a.update({
                    re.sub(" \d{2}:\d{2}:\d{2}\.\d{6}\+00:00", "",
                           str(status['created_at'])):
                    order(z.group(1))
                })
                json.dump(a, f)
        else:
            s = "\n本日あなたが引いた結果は【{}】です。".format(nstr["omikuji_lack"])
            mastodon = Mastodon(
                client_id="login\\cred.txt",
                access_token="login\\auth.txt",
                api_base_url=open("login\\instance.txt").read())  # インスタンス
            toot.toot_res(mastodon,
                          "@" + account['acct'] +
                          " 一日一回ですよ!\n朝9時頃を越えたらもう一度お願いします!" + s,
                          "public",
                          status["id"],
                          sec=3)
            return
    except FileNotFoundError:
        print("◇hit_New")
        post = conv.rand_w('bot\\game\\' + 'kuji' +
                           '.txt') + " " + "@" + account['acct'] + " #こおりみくじ"
        c = {}
        c.update({"omikuji_time": str(status["created_at"])})
        z = re.search("【(.+)】", post)
        c.update({"omikuji_lack": z.group(1)})
        with codecs.open('data\\dic_time\\' + account["acct"] + '.json', 'w',
                         'UTF-8') as f:
            json.dump(c, f)
        with codecs.open(
                'data\\dic_time\\omikuji_diary\\' + account["acct"] + '.json',
                'w', 'UTF-8') as f:
            a = {}
            a.update({
                re.sub(" \d{2}:\d{2}:\d{2}\.\d{6}\+00:00", "",
                       str(status['created_at'])):
                order(z.group(1))
            })
            json.dump(a, f)
    except json.decoder.JSONDecodeError:
        print(traceback.format_exc())
        print("◇hit_ReNew")
        post = conv.rand_w('bot\\game\\' + 'kuji' +
                           '.txt') + " " + "@" + account['acct'] + " #こおりみくじ"
        c = {}
        c.update({"omikuji_time": str(status["created_at"])})
        z = re.search("【(.+)】", post)
        c.update({"omikuji_lack": z.group(1)})
        with codecs.open('data\\dic_time\\' + account["acct"] + '.json', 'w',
                         'UTF-8') as f:
            json.dump(c, f)
        with codecs.open(
                'data\\dic_time\\omikuji_diary\\' + account["acct"] + '.json',
                'w', 'UTF-8') as f:
            a = {}
            a.update({
                re.sub(" \d{2}:\d{2}:\d{2}\.\d{6}\+00:00", "",
                       str(status['created_at'])):
                order(z.group(1))
            })
            json.dump(a, f)
    return post