Ejemplo n.º 1
0
async def intone(ctx, arg1='emp'):
    guild_id = ctx.guild.id
    str_id = str(guild_id)
    guild_deta = ctrl_db.get_guild(str_id)
    if isinstance(guild_deta, type(None)):
        prefix = '?'
    else:
        prefix = guild_deta.prefix

    struid = str(ctx.author.id)

    if arg1 == 'emp':
        await ctx.send('引数が不足してるで。{}helpを見てみ。'.format(prefix))
        return

    try:
        r_range = float(arg1)
    except:
        await ctx.send('使い方が正しくないで。{}helpを見てみ。'.format(prefix))
        return

    if r_range >= 0.0 and r_range <= 2.0:
        ctrl_db.set_readrange(r_range, struid)
    else:
        await ctx.send('数値が正しくないで。0.0~2.0を指定してくれな。デフォルトは1.0や。')
Ejemplo n.º 2
0
async def pitch(ctx, arg1='emp'):
    guild_id = ctx.guild.id
    str_id = str(guild_id)
    # プレフィックスを取得
    guild_deta = ctrl_db.get_guild(str_id)
    if isinstance(guild_deta, type(None)):
        prefix = '?'
    else:
        prefix = guild_deta.prefix

    struid = str(ctx.author.id)

    if arg1 == 'emp':
        await ctx.send('引数が不足してるで。{}helpを見てみ。'.format(prefix))
        return

    try:
        pitch = float(arg1)
    except:
        await ctx.send('使い方が正しくないで。{}helpを見てみ。'.format(prefix))
        return

    if pitch >= 0.0 and pitch <= 2.0:
        ctrl_db.set_readpitch(pitch, struid)
        u_st = ctrl_db.get_user(str(ctx.author.id))
        spk = spk_to_char(u_st.speaker)
        await ctx.send('{}のステータス 話者:{} 高さ:{} 速度:{} 抑揚:{}'.format(
            ctx.author.mention, spk, u_st.pitch, u_st.speed, u_st.r_range))
    else:
        await ctx.send('数値が正しくないで。0.0~2.0を指定してくれな。デフォルトは1.2や。')
Ejemplo n.º 3
0
async def pitch(ctx, arg1='emp'):
    guild_id = ctx.guild.id
    str_id = str(guild_id)
    guild_deta = ctrl_db.get_guild(str_id)
    if isinstance(guild_deta, type(None)):
        prefix = '?'
    else:
        prefix = guild_deta.prefix

    struid = str(ctx.author.id)

    if arg1 == 'emp':
        await ctx.send('引数が不足してるで。{}helpを見てみ。'.format(prefix))
        return

    try:
        pitch = float(arg1)
    except:
        await ctx.send('使い方が正しくないで。{}helpを見てみ。'.format(prefix))
        return

    if pitch >= 0.5 and pitch <= 2.0:
        ctrl_db.set_readpitch(pitch, struid)
        await ctx.send('声の高さを{}に設定したで。'.format(pitch))
    else:
        await ctx.send('数値が正しくないで。0.5~2.0を指定してくれな。デフォルトは1.0や。')
Ejemplo n.º 4
0
async def speed(ctx, arg1='emp'):
    guild_id = ctx.guild.id
    str_id = str(guild_id)
    guild_deta = ctrl_db.get_guild(str_id)
    if isinstance(guild_deta, type(None)):
        prefix = '?'
    else:
        prefix = guild_deta.prefix

    struid = str(ctx.author.id)

    if arg1 == 'emp':
        await ctx.send('引数が不足してるで。{}helpを見てみ。'.format(prefix))
        return

    try:
        speed = float(arg1)
    except:
        await ctx.send('使い方が正しくないで。{}helpを見てみ。'.format(prefix))
        return

    if speed >= 0.5 and speed <= 4.0:
        ctrl_db.set_readspeed(speed, struid)
        await ctx.send('読み上げ速度を{}に設定したで。'.format(speed))
    else:
        await ctx.send('数値が正しくないで。0.5~4.0を指定してくれな。デフォルトは1.0や。')
Ejemplo n.º 5
0
def add_guild_db(guild):
    str_id = str(guild.id)
    guilds = ctrl_db.get_guild(str_id)
    # デフォルトのprefixは'?'
    prefix = '?'

    if guilds is None:
        ctrl_db.add_guild(str_id, guild.name, prefix)
Ejemplo n.º 6
0
def add_guild_db(guild):
    str_id = str(guild.id)
    guilds = ctrl_db.get_guild(str_id)
    # デフォルトのprefixは'?'
    prefix = '?'

    if isinstance(guilds, type(None)):
        ctrl_db.add_guild(str_id, guild.name, prefix)
Ejemplo n.º 7
0
async def spk(ctx, arg1='emp'):
    global channel
    cand = arg1
    guild_id = ctx.guild.id
    str_id = str(guild_id)
    guild_deta = ctrl_db.get_guild(str_id)
    if isinstance(guild_deta, type(None)):
        prefix = '?'
    else:
        prefix = guild_deta.prefix

    if cand == 'emp':
        await ctx.send('引数が不足してるで。{}spk helpを見てみ。'.format(prefix))
        return

    if cand == 'help':
        embed = discord.Embed(title='{}spk'.format(prefix),
                              description='声を変えるコマンド')
        embed.add_field(name='{}spk yukari'.format(prefix),
                        value='ゆかりさんに変身',
                        inline=False)
        embed.add_field(name='{}spk maki'.format(prefix),
                        value='マキマキに変身',
                        inline=False)
        embed.add_field(name='{}spk ai'.format(prefix),
                        value='アイちゃんに変身',
                        inline=False)
        embed.add_field(name='{}spk kou'.format(prefix),
                        value='コウ先生に変身',
                        inline=False)

        await ctx.send(embed=embed)
    else:
        # 呼び出したチャンネルでコマンドが叩かれた場合
        if ctx.channel.id == channel[guild_id]:
            if cand not in sps:
                # 引き数のキャラが存在しない場合
                await ctx.channel.send('おっと、そのキャラは未実装だ。すまねえ。')
                return
            elif cand == 'yukari':
                # ゆかりの場合
                cand = 'sumire'
            elif cand == 'ai':
                # アイの場合
                cand = 'anzu'
            elif cand == 'kou':
                # コウの場合
                cand = 'osamu'

            # 話者を設定
            ctrl_db.set_user(str(ctx.author.id), cand)
Ejemplo n.º 8
0
async def help(ctx):
    str_id = str(ctx.guild.id)
    guild_deta = ctrl_db.get_guild(str_id)
    if isinstance(guild_deta, type(None)):
        prefix = '?'
    else:
        prefix = guild_deta.prefix

    embed = discord.Embed(title='喋太郎', description='メッセージを読み上げるBotやで。')
    embed.add_field(name='{}summon'.format(prefix),
                    value='わいをボイスチャンネルに呼ぶコマンドや。',
                    inline=False)
    embed.add_field(name='{}bye'.format(prefix),
                    value='わいをボイスチャンネルから追い出す時に使うんや。',
                    inline=False)
    embed.add_field(name='{}spk'.format(prefix),
                    value='声を変えるのに使うで。詳しくは、「{}spk help」を見てほしい。'.format(prefix),
                    inline=False)
    embed.add_field(
        name='{}set_prefix'.format(prefix),
        value='コマンドプレフィックスを変更するのに使うで。「{}set_prefix ??」みたいにするといいぞ。'.format(
            prefix),
        inline=False)
    embed.add_field(name='{}stop'.format(prefix),
                    value='わいが喋ってるのを黙らせるで。',
                    inline=False)
    embed.add_field(
        name='{}wbook'.format(prefix),
        value='読み仮名の登録とかができるで。詳しくは、「{}wbook help」を見て欲しい。'.format(prefix),
        inline=False)
    embed.add_field(name='{}readname'.format(prefix),
                    value='コマンドの後に「on」か「off」をつけることで、名前を読み上げるか切り替えられるで。',
                    inline=False)
    embed.add_field(name='{}speed'.format(prefix),
                    value='コマンドの後に0.5~4.0の小数をつけることで、読み上げ速度が変わるで。デフォルトは1.0や。',
                    inline=False)
    embed.add_field(name='{}intone'.format(prefix),
                    value='コマンドの後に0.0~2.0の小数をつけることで、抑揚が変わるで。デフォルトは1.1や。',
                    inline=False)
    embed.add_field(name='{}pitch'.format(prefix),
                    value='コマンドの後に0.0~2.0の小数をつけることで、高さが変わるで。デフォルトは1.2や。',
                    inline=False)
    embed.add_field(name='{}status'.format(prefix),
                    value='現在の音声設定を表示するで。',
                    inline=False)
    embed.add_field(name='{}uranai'.format(prefix),
                    value='おみくじが引けるで。結果は日替わりや。',
                    inline=False)

    await ctx.send(embed=embed)
Ejemplo n.º 9
0
async def on_ready():
    print('Logged in as')
    print(bot.user.name)
    print('Guild Nameの初期化開始')
    for guild in bot.guilds:
        old_guild = ctrl_db.get_guild(str(guild.id))
        if old_guild is None:
            continue
        if guild.name != old_guild.name:
            ctrl_db.set_guild_name(str(guild.id), guild.name)
    print('完了')
    activ = discord.Game('{}servers'.format(len(bot.voice_clients)))
    await bot.change_presence(activity=activ)
    print('------')
Ejemplo n.º 10
0
async def spk(ctx, arg1='emp'):
    global channel
    cand = arg1
    guild_id = ctx.guild.id
    str_id = str(guild_id)
    guild_deta = ctrl_db.get_guild(str_id)
    if isinstance(guild_deta, type(None)):
        prefix = '?'
    else:
        prefix = guild_deta.prefix

    if cand == 'emp':
        await ctx.send('引数が不足してるで。{}spk helpを見てみ。'.format(prefix))
        return

    if cand == 'help':
        embed = discord.Embed(title='{}spk'.format(prefix),
                              description='声を変えるコマンド')
        embed.add_field(name='{}spk yukari'.format(prefix),
                        value='ゆかりさんに変身',
                        inline=False)
        embed.add_field(name='{}spk maki'.format(prefix),
                        value='マキマキに変身',
                        inline=False)
        embed.add_field(name='{}spk ai'.format(prefix),
                        value='アイちゃんに変身',
                        inline=False)
        embed.add_field(name='{}spk kou'.format(prefix),
                        value='コウ先生に変身',
                        inline=False)

        await ctx.send(embed=embed)
    else:
        # 呼び出したチャンネルでコマンドが叩かれた場合
        if ctx.channel == channel.get(guild_id):
            if cand not in sps:
                # 引き数のキャラが存在しない場合
                await ctx.channel.send('おっと、そのキャラは未実装だ。すまねえ。')
                return
            else:
                cand = char_to_spk(cand)

            # 話者を設定
            ctrl_db.set_user(str(ctx.author.id), cand)
            u_st = ctrl_db.get_user(str(ctx.author.id))
            spk = spk_to_char(u_st.speaker)
            await ctx.send('{}のステータス 話者:{} 高さ:{} 速度:{} 抑揚:{}'.format(
                ctx.author.mention, spk, u_st.pitch, u_st.speed, u_st.r_range))
Ejemplo n.º 11
0
async def readname(ctx, arg1='emp'):
    guild_id = ctx.guild.id
    str_id = str(guild_id)
    guild_deta = ctrl_db.get_guild(str_id)
    if isinstance(guild_deta, type(None)):
        prefix = '?'
    else:
        prefix = guild_deta.prefix

    if arg1 == 'emp':
        await ctx.send('引数が不足してるで。{}helpを見てみ。'.format(prefix))
    elif arg1 == 'on':
        ctrl_db.set_nameread(True, str_id)
    elif arg1 == 'off':
        ctrl_db.set_nameread(False, str_id)
    else:
        await ctx.send('使い方が正しくないで。{}helpを見てみ。'.format(prefix))
Ejemplo n.º 12
0
async def summon(ctx):
    global channel
    # global guild_id
    guild_id = ctx.guild.id  # サーバIDを取得
    vo_ch = ctx.author.voice  # 召喚した人が参加しているボイスチャンネルを取得

    # サーバを登録
    add_guild_db(ctx.guild)

    # サーバのプレフィックスを取得
    guild_deta = ctrl_db.get_guild(str(guild_id))
    if guild_deta is None:
        prefix = '?'
    else:
        prefix = guild_deta.prefix

    # 召喚した人がボイスチャンネルにいた場合
    if vo_ch is not None:
        # 召喚された時、voiceに情報が残っている場合フラグを立てる
        is_dust = False
        for vc in bot.voice_clients:
            if vc.guild.id == guild_id:
                is_dust = True
                ctrlvc = vc
        # ボイスチャンネルにすでにいたならば移動、そうでないなら接続(再接続なし)
        if is_dust == True:
            await ctrlvc.move_to(vo_ch.channel)
        else:
            await vo_ch.channel.connect(timeout=10.0, reconnect=False)
        channel[guild_id] = ctx.channel
        noties = get_notify(ctx)
        ctrl_db.set_session(
            datetime.datetime.now().replace(minute=0, second=0, microsecond=0),
            len(bot.voice_clients))
        activ = discord.Game('{}servers'.format(len(bot.voice_clients)))
        await bot.change_presence(activity=activ)
        await ctx.channel.send(
            '毎度おおきに。わいは喋太郎や。"{}help"コマンドで使い方を表示するで'.format(prefix))
        for noty in noties:
            await ctx.channel.send(noty)
        if len(noties) != 0:
            await ctx.channel.send(
                '喋太郎に何かあれば、だーやまんのお題箱( https://odaibako.net/u/gamerkohei )までお願いします。\r喋太郎の開発、運用等にご協力をお願いします🙌\rhttps://fantia.jp/gamerkohei '
            )
    else:
        await ctx.channel.send('あんたボイスチャンネルおらへんやんけ!')
Ejemplo n.º 13
0
async def spk(ctx, arg1='emp'):
    global channel
    cand = arg1
    guild_id = ctx.guild.id
    str_id = str(guild_id)
    guild_deta = ctrl_db.get_guild(str_id)

    spk_name = [
        None, "show(男性)", "haruka(女性)", "hikari(女性)", "takeru(男性)",
        "santa(サンタ)", "bear(凶暴なクマ)"
    ]

    if isinstance(guild_deta, type(None)):
        prefix = '?'
    else:
        prefix = guild_deta.prefix

    if cand == 'emp':
        await ctx.send('引数が不足してるで。{}spk helpを見てみ。'.format(prefix))
        return

    if cand == 'help':
        embed = discord.Embed(title='{}spk'.format(prefix),
                              description='声を変えるコマンド')
        for i in range(1, 7):
            embed.add_field(name='{}spk {}'.format(prefix, i),
                            value='{}に変身'.format(spk_name[i]),
                            inline=False)

        await ctx.send(embed=embed)
    else:
        # 呼び出したチャンネルでコマンドが叩かれた場合
        if ctx.channel.id == channel[guild_id]:
            if cand not in [str(i) for i in range(1, 7)]:
                # 引き数のキャラが存在しない場合
                await ctx.channel.send('おっと、そのキャラは未実装だ。すまねえ。')
                return

            # 話者を設定
            ctrl_db.set_user(str(ctx.author.id), cand)
            await ctx.channel.send('話者を{}に設定したで。'.format(spk_name[int(cand)]))
Ejemplo n.º 14
0
async def summon(ctx):
    global voice
    global channel
    # global guild_id
    guild_id = ctx.guild.id  # サーバIDを取得
    vo_ch = ctx.author.voice  # 召喚した人が参加しているボイスチャンネルを取得

    # サーバを登録
    add_guild_db(ctx.guild)

    # サーバのプレフィックスを取得
    guild_deta = ctrl_db.get_guild(str(guild_id))
    if isinstance(guild_deta, type(None)):
        prefix = '?'
    else:
        prefix = guild_deta.prefix

    # 召喚された時、voiceに情報が残っている場合
    if guild_id in voice:
        await voice[guild_id].disconnect()
        del voice[guild_id]
        del channel[guild_id]
    # 召喚した人がボイスチャンネルにいた場合
    if not isinstance(vo_ch, type(None)):
        voice[guild_id] = await vo_ch.channel.connect()
        channel[guild_id] = ctx.channel.id
        noties = get_notify(ctx)
        await ctx.channel.send(
            '毎度おおきに。わいは喋太郎や。"{}help"コマンドで使い方を表示するで'.format(prefix))
        for noty in noties:
            await ctx.channel.send(noty)
        if len(noties) != 0:
            await ctx.channel.send(
                '喋太郎に何かあれば、だーやまんのお題箱( https://odaibako.net/u/gamerkohei )までお願いします。\r喋太郎の開発、運用等にご協力をお願いします🙌\rhttps://fantia.jp/gamerkohei '
            )
    else:
        await ctx.channel.send('あんたボイスチャンネルおらへんやんけ!')
Ejemplo n.º 15
0
async def on_message(message):
    print(message)
    # if message.author.bot:
    #     return
    global voice
    global channel

    mess_id = message.author.id  # メッセージを送った人のユーザID

    # ギルドIDがない場合、DMと判断する
    if isinstance(message.guild, type(None)):
        # 管理人からのDMだった場合
        if message.author.id == manager:
            #コマンド操作になっているか
            if message.content.startswith('?'):
                await message.channel.send('コマンドを受け付けたで')
                await bot.process_commands(message)  # メッセージをコマンド扱いにする
                return
            else:
                await message.channel.send('コマンド操作をしてくれ')
                return
        else:
            await message.channel.send(
                '喋太郎に何かあれば、だーやまんのお題箱( https://odaibako.net/u/gamerkohei )までお願いします。'
            )
            return

    guild_id = message.guild.id  # サーバID

    # ユーザ情報(speaker)を取得
    user = ctrl_db.get_user(str(mess_id))
    if isinstance(user, type(None)):
        # ユーザ情報がなければ、dbへ登録。話者はあおい。
        ctrl_db.add_user(str(mess_id), message.author.name, "1")
        user = ctrl_db.get_user(str(mess_id))

    # サーバのプレフィックスを取得
    guild_deta = ctrl_db.get_guild(str(guild_id))
    if isinstance(guild_deta, type(None)):
        prefix = '?'
    else:
        prefix = guild_deta.prefix

    # コマンドだった場合
    if message.content.startswith(prefix):
        # prefixは?へ変換する
        message.content = message.content.replace(prefix, '?', 1)
        await bot.process_commands(message)  # メッセージをコマンド扱いにする
        return

    # 召喚されていなかった場合
    if guild_id not in channel:
        return

    str_guild_id = str(guild_id)

    # メッセージを、呼び出されたチャンネルで受信した場合
    if message.channel.id == channel[guild_id]:
        # URLを、"URL"へ置換
        get_msg = re.sub(r'http(s)?://([\w-]+\.)+[\w-]+(/[-\w ./?%&=]*)?',
                         'URL', message.content)
        # reactionの置換
        get_msg = get_msg.replace('<:', '')
        get_msg = re.sub(r':[0-9]*>', '', get_msg)
        # mention と channel_mentionを名前へ置換
        mn_list = message.raw_mentions
        ch_list = message.raw_channel_mentions
        # IDに対応する名前の辞書を作成
        mn_dict = {}
        ch_dict = {}
        # mentionの、ユーザネームへの置換
        for ment in mn_list:
            # 自身へのメンションかどうかで、Keyを変える
            if ment == mess_id:
                mn_dict['<@!{}>'.format(
                    str(ment))] = message.guild.get_member(ment).name
            else:
                mn_dict['<@{}>'.format(
                    str(ment))] = message.guild.get_member(ment).name
        # channel_mentionの、チャンネル名への置換
        for cnls in ch_list:
            ch_dict['<#{}>'.format(
                str(cnls))] = message.guild.get_channel(cnls).name
        # 変換テーブルの作成
        for me_key in mn_dict.keys():
            get_msg = get_msg.replace(me_key, mn_dict[me_key], 1)
        for ch_key in ch_dict.keys():
            get_msg = get_msg.replace(ch_key, ch_dict[ch_key], 1)
        # 読み上げモード確認
        is_nameread = ctrl_db.get_guild(str_guild_id).is_nameread
        # モードによって名前を追加するか検討
        if is_nameread == True:
            get_msg = '{}、'.format(message.author.display_name) + get_msg
        # 置換文字のリストを取得
        words = ctrl_db.get_dict(str_guild_id)
        for word in words:
            get_msg = get_msg.replace(word.word, word.read)
        get_msg = get_msg.replace('<', '').replace('>', '')
        # print(get_msg)
        #リクエスト回数のカウント
        ctrl_db.set_reqcount(datetime.date.today(),
                             datetime.datetime.now().hour)
        # メッセージを、音声ファイルを作成するモジュールへ投げる処理
        try:
            rawfile = await knockApi(get_msg, user.speaker, user.speed,
                                     user.r_range, user.pitch, str_guild_id)
        # 失敗した場合(ログは吐くようにしたい)
        except Exception as e:
            await message.channel.send(
                'ちょいとエラー起きたみたいや。少し待ってからメッセージ送ってくれな。\n{}'.format(e))
            return

        # 音声ファイルを再生中の場合再生終了まで止まる
        while (voice[guild_id].is_playing()):
            # 他の処理をさせて1秒待機
            await asyncio.sleep(1)
        # 再生処理
        voice_mess = './cache/{}/{}'.format(str_guild_id,
                                            rawfile)  # rawファイルのディレクトリ
        voice[guild_id].play(
            discord.FFmpegPCMAudio(voice_mess))  # エンコードして音声チャンネルで再生
        while (voice[guild_id].is_playing()):
            # 他の処理をさせて1秒待機
            await asyncio.sleep(1)
        os.remove(voice_mess)  #rawファイルの削除
Ejemplo n.º 16
0
async def wbook(ctx, arg1='emp', arg2='emp', arg3='emp'):
    guild_id = ctx.guild.id
    str_id = str(guild_id)
    # プレフィックスの取得
    guild_deta = ctrl_db.get_guild(str_id)
    if isinstance(guild_deta, type(None)):
        prefix = '?'
    else:
        prefix = guild_deta.prefix

    if arg1 == 'help':
        embed = discord.Embed(
            title='{}wbook'.format(prefix),
            description='辞書を操作するコマンド。データはサーバ毎に分けられてるから安心してな。')
        embed.add_field(
            name='{}wbook add 単語 よみがな'.format(prefix),
            value='読み上げ文にこの単語があった場合、よみがなの通りに読み変えるで。\r例:{}wbook add 男の娘 おとこのこ'.
            format(prefix),
            inline=False)
        embed.add_field(name='{}wbook list'.format(prefix),
                        value='登録した単語の一覧を表示するで。',
                        inline=False)
        embed.add_field(name='{}wbook search 単語'.format(prefix),
                        value='単語を検索し、読み仮名と辞書番号を表示するで。そこになければないですね。',
                        inline=False)
        embed.add_field(name='{}wbook delete 番号'.format(prefix),
                        value='listで表示された辞書番号の単語を削除するで',
                        inline=False)
        embed.add_field(name='{}wbook alldel'.format(prefix),
                        value='辞書を全削除するで。復元できないから注意やぞ。',
                        inline=False)

        await ctx.send(embed=embed)

    elif arg1 == 'list':
        # リスト表示
        words = ctrl_db.get_dict(str_id)
        embed = discord.Embed(title='辞書一覧')
        embed.add_field(name='番号', value='単語:よみがな', inline=False)
        for i, word in enumerate(words, start=1):
            if i % 15 == 0:
                await ctx.send(embed=embed)
                embed = discord.Embed(title=str(word.id),
                                      description='{}:{}'.format(
                                          word.word, word.read))
            else:
                embed.add_field(name=str(word.id),
                                value='{}:{}'.format(word.word, word.read),
                                inline=False)

        await ctx.send(embed=embed)

    elif arg1 == 'add':
        if arg2 == 'emp' or arg3 == 'emp':
            await ctx.send('引数が不足してるで。{}wbook helpを見てみ。'.format(prefix))
        # 辞書追加、あるいはアップデート
        try:
            ctrl_db.add_dict(arg2, arg3, str_id)
            await ctx.send('{}:{}を辞書に追加したで。'.format(arg2, arg3))
        except:
            await ctx.send('すまん、辞書の追加に失敗したわ。')

    elif arg1 == 'delete':
        if arg2 == 'emp':
            await ctx.send('引数が不足してるで。{}wbook helpを見てみ。'.format(prefix))
        elif arg2.isdecimal():
            # 削除処理
            is_del = ctrl_db.del_dict(int(arg2), str_id)
            if is_del == True:
                await ctx.send('削除成功や。')
            else:
                await ctx.send('その番号の単語は登録されてないで。')
        else:
            await ctx.send('使い方が正しくないで。{}wbook helpを見てみ。'.format(prefix))
    elif arg1 == 'alldel':
        try:
            ctrl_db.del_all_dict(str_id)
            await ctx.send('全削除に成功したで。')
        except:
            await ctx.send('全削除に失敗したわ。すまんやで。')
    elif arg1 == 'search':
        if arg2 == 'emp':
            await ctx.send('引数が不足してるで。{}wbook helpを見てみ。'.format(prefix))
        else:
            result = ctrl_db.search_dict(str_id, arg2)
            if result is None:
                await ctx.send('見つからへんかったわ。すまんな。')
            else:
                await ctx.send('{}を{}と読むで。辞書番号は{}や。'.format(
                    result.word, result.read, result.id))
    else:
        await ctx.send('使い方が正しくないで。{}wbook helpを見てみ。'.format(prefix))
Ejemplo n.º 17
0
async def on_message(message):
    # botは読み上げない
    if message.author.bot:
        return

    global channel

    mess_id = message.author.id  # メッセージを送った人のユーザID

    # ギルドIDがない場合、DMと判断する
    if message.guild is None:
        # 管理人からのDMだった場合
        if message.author.id == manager:
            #コマンド操作になっているか
            if message.content.startswith('?'):
                await message.channel.send('コマンドを受け付けたで')
                await bot.process_commands(message)  # メッセージをコマンド扱いにする
                return
            else:
                await message.channel.send('コマンド操作をしてくれ')
                return
        else:
            await message.channel.send(
                '喋太郎に何かあれば、だーやまん( https://twitter.com/gamerkohei )までリプライかDMをお願いします。'
            )
            return

    guild_id = message.guild.id  # サーバID

    # ユーザ情報(speaker)を取得
    user = ctrl_db.get_user(str(mess_id))
    if user is None:
        # ユーザ情報がなければ、dbへ登録。話者はsumire
        ctrl_db.add_user(str(mess_id), message.author.name, 'sumire')
        user = ctrl_db.get_user(str(mess_id))

    # サーバのプレフィックスを取得
    guild_deta = ctrl_db.get_guild(str(guild_id))
    if guild_deta is None:
        prefix = '?'
    else:
        prefix = guild_deta.prefix

    # コマンドだった場合
    if message.content.startswith(prefix):
        # prefixは?へ変換する
        message.content = message.content.replace(prefix, '?', 1)
        await bot.process_commands(message)  # メッセージをコマンド扱いにする
        return

    # 召喚されていなかった場合
    ## VCに接続されているか判断
    for vc in bot.voice_clients:
        if vc.guild.id == guild_id:
            ctrlvc = vc
            break

    try:
        ctrlvc
    except UnboundLocalError:
        return

    str_guild_id = str(guild_id)

    # メッセージを、呼び出されたチャンネルで受信した場合
    if message.channel == channel.get(guild_id):
        # this is easteregg01
        if message.content == 'はつざつ「屈辱だ…。」':
            path = 'images/kutsujoku.jpg'
            if os.path.isfile(path):
                with open(path, mode='rb') as f:
                    htzt_f = discord.File(f)
                    await message.channel.send(file=htzt_f)
                    return
        # this is easteregg03
        if message.content == 'ゆるしてにゃん':
            path = 'images/yurushite{}.jpg'.format(random.randint(1, 9))
            if os.path.isfile(path):
                yurusite_f = open(path, mode='rb')
                yurushite = discord.File(yurusite_f)
        # URLを、"URL"へ置換
        get_msg = re.sub(r'http(s)?://([\w-]+\.)+[\w-]+(/[-\w ./?%&=]*)?',
                         'URL', message.content)
        # reactionの置換
        get_msg = get_msg.replace('<:', '')
        get_msg = re.sub(r':[0-9]*>', '', get_msg)
        # mention と channel_mentionを名前へ置換
        mn_list = message.raw_mentions
        ch_list = message.raw_channel_mentions
        # IDに対応する名前の辞書を作成
        mn_dict = {}
        ch_dict = {}
        # mentionの、ユーザネームへの置換
        for ment in mn_list:
            # 自身へのメンションかどうかで、Keyを変える
            if ment == mess_id:
                mn_dict['<@!{}>'.format(
                    str(ment))] = message.guild.get_member(ment).name
            else:
                mn_dict['<@{}>'.format(
                    str(ment))] = message.guild.get_member(ment).name
        # channel_mentionの、チャンネル名への置換
        for cnls in ch_list:
            ch_dict['<#{}>'.format(
                str(cnls))] = message.guild.get_channel(cnls).name
        # 変換テーブルの作成
        for me_key in mn_dict.keys():
            get_msg = get_msg.replace(me_key, mn_dict[me_key], 1)
        for ch_key in ch_dict.keys():
            get_msg = get_msg.replace(ch_key, ch_dict[ch_key], 1)
        # 置換文字のリストを取得
        words = ctrl_db.get_dict(str_guild_id)
        for word in words:
            get_msg = get_msg.replace(word.word, word.read)
        get_msg = get_msg.replace('<', '').replace('>', '')
        # 読み上げモード確認
        is_nameread = ctrl_db.get_guild(str_guild_id).is_nameread
        # モードによって名前を追加するか検討
        if is_nameread == True:
            get_msg = '{}、'.format(message.author.display_name) + get_msg
        #リクエスト回数のカウント
        ctrl_db.set_reqcount(datetime.date.today(),
                             datetime.datetime.now().hour)
        # メッセージを、音声ファイルを作成するモジュールへ投げる処理
        try:
            rawfile = await knockApi(get_msg, user.speaker, user.speed,
                                     user.r_range, user.pitch, str_guild_id)
        # 失敗した場合(ログは吐くようにしたい)
        except:
            await message.channel.send(
                'To {} ちょいとエラー起きたみたいや。少し待ってからメッセージ送ってくれな。'.format(
                    message.author.name))
            try:
                yurushite_f.close()
            except NameError:
                pass
            return

        # 音声ファイルを再生中の場合再生終了まで止まる
        while (ctrlvc.is_playing()):
            # 他の処理をさせて1秒待機
            await asyncio.sleep(1)
        # 再生処理
        voice_mess = './cache/{}/{}'.format(str_guild_id,
                                            rawfile)  # rawファイルのディレクトリ
        ctrlvc.play(
            discord.FFmpegPCMAudio(
                voice_mess,
                before_options='-f s16be -ar 16k -ac 1'))  # エンコードして音声チャンネルで再生

        try:
            await message.channel.send(file=yurushite)
            yurusite_f.close()
        except NameError:
            pass
        await asyncio.sleep(0.5)
        os.remove(voice_mess)  #rawファイルの削除
Ejemplo n.º 18
0
async def wbook(ctx, arg1='emp', arg2='emp', arg3='emp'):
    guild_id = ctx.guild.id
    str_id = str(guild_id)
    guild_deta = ctrl_db.get_guild(str_id)
    if isinstance(guild_deta, type(None)):
        prefix = '?'
    else:
        prefix = guild_deta.prefix

    if arg1 == 'help':
        embed = discord.Embed(
            title='{}wbook'.format(prefix),
            description='辞書を操作するコマンド。データはサーバ毎に分けられてるから安心してな。')
        embed.add_field(
            name='{}wbook add 単語 よみがな'.format(prefix),
            value='読み上げ文にこの単語があった場合、よみがなの通りに読み変えるで。\r例:{}wbook add 男の娘 おとこのこ'.
            format(prefix),
            inline=False)
        embed.add_field(name='{}wbook list'.format(prefix),
                        value='登録した単語の一覧を表示するで。',
                        inline=False)
        embed.add_field(name='{}wbook delete 番号'.format(prefix),
                        value='listで表示された辞書番号の単語を削除するで',
                        inline=False)

        await ctx.send(embed=embed)

    elif arg1 == 'list':
        # リスト表示
        words = ctrl_db.get_dict(str_id)
        embed = discord.Embed(title='辞書一覧')
        embed.add_field(name='番号', value='単語:よみがな', inline=False)
        for i, word in enumerate(words, start=1):
            if i % 15 == 0:
                await ctx.send(embed=embed)
                embed = discord.Embed(title=str(word.id),
                                      description='{}:{}'.format(
                                          word.word, word.read))
            else:
                embed.add_field(name=str(word.id),
                                value='{}:{}'.format(word.word, word.read),
                                inline=False)

        await ctx.send(embed=embed)

    elif arg1 == 'add':
        if arg2 == 'emp' or arg3 == 'emp':
            await ctx.send('引数が不足してるで。{}wbook helpを見てみ。'.format(prefix))
        # 辞書追加、あるいはアップデート
        ctrl_db.add_dict(arg2, arg3, str_id)
        await ctx.send('登録したで。')

    elif arg1 == 'delete':
        if arg2 == 'emp':
            await ctx.send('引数が不足してるで。{}wbook helpを見てみ。'.format(prefix))
        elif arg2.isdecimal():
            # 削除処理
            is_del = ctrl_db.del_dict(int(arg2), str_id)
            if is_del == True:
                await ctx.send('削除成功や。')
            else:
                await ctx.send('その番号の単語は登録されてないで。')
        else:
            await ctx.send('使い方が正しくないで。{}wbook helpを見てみ。'.format(prefix))
    else:
        await ctx.send('使い方が正しくないで。{}wbook helpを見てみ。'.format(prefix))