Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Wed Jul 8 23:23:15 2020
- @author: tsutitire
- """
- import discord
- import random
- client = discord.Client()
- TOKEN = 'Your Token'
- indalpha = 0
- @client.event
- async def on_ready():
- #コンソールにメッセージを送信
- print('loggined!')
- print("haraseu bot")
- #挨拶
- channel = client.get_channel(Your talking channel ID)
- await channel.send("むにゃ...おはらせう!")
- #アクティビティの設定
- activity = discord.Game(name="Help:haraseu/help")
- await client.change_presence(status=discord.Status.idle, activity=activity)
- @client.event
- async def on_message(message):
- #ボットはお帰り下さい
- if message.author.bot:
- return
- global indalpha
- #ファイル読み込み
- path = 'haraseu.txt'
- f = open(path,"r")
- words = f.read()
- words = str(words)
- f.close()
- #変数初期化
- indalpha = 0
- #ランダム=>抜きだし
- rnd = random.randrange(words.count(";") / 2 + 1)
- for dummy in range((rnd * 2 - 2)):
- indalpha = words.find(";",indalpha + 1)
- indbeta = words.find(";",indalpha + 1)
- data = words[indalpha + 1:indbeta]
- #送信
- await message.channel.send(data)
- #ヘルプ
- if message.content.startswith("haraseu/help"):
- embed = discord.Embed(title="The help of HARASEU",description="はらせうBOTの使い方せう" )
- #embed.set_image(url="https://b.imgef.com/POuypFI.png")
- embed.add_field(name="haraseu/learn",value="入力された文字を覚えるせう セミコロンは使わないでほしいせう(e.g. haraseu/learn はらせう)")
- embed.add_field(name="haraseu/remove",value="IDに対応する言葉を削除するせう (e.g. haraseu/remove 234)")
- embed.add_field(name="haraseu/list",value="文字のリストを出力するせう (e.g. haraseu/list)")
- #送信
- await message.channel.send(embed=embed)
- #学習
- if message.content.startswith("haraseu/learn"):
- #ファイル読み込み
- path = 'haraseu.txt'
- f = open(path,"r")
- words = f.read()
- f.close()
- #ファイル書き込み
- f = open(path,"w")
- #--データを変数へ
- data = str(message.content[14:])
- #--セミコロンはだめです
- if data.find(";") != -1:
- await message.channel.send("セミコロンつかうとエラー起きちゃうからやめて欲しいせう~")
- return
- #--書き込みデータ作成
- data2 = str(words) + ";" + str(data) + ";"
- data2 = str(data2)
- #--ID作成
- yid = data2.count(";")
- yid = yid/2
- #--書き込み
- f.write(data2)
- f.close
- await message.channel.send("アップロード完了だせう! ID:" + str(yid))
- #リスト
- if message.content.startswith("haraseu/list"):
- #中身取得だせう
- path = 'haraseu.txt'
- f = open(path,"r")
- words = f.read()
- f.close
- #送信
- await message.channel.send(str(words))
- #削除(ごり押し)
- if message.content.startswith("haraseu/remove"):
- #中身取得だせう
- path = 'haraseu.txt'
- f = open(path,"r")
- words = f.read()
- f.close
- #変数リセット
- indalpha = 0
- #ID=>位置変換
- for dummy in range((int(message.content[15:]) * 2 - 2)):
- indalpha = words.find(";",indalpha + 1)
- indbeta = words.find(";",indalpha + 1)
- indalpha = indalpha - 1
- #データ作成
- data = words[:indalpha] + words[indbeta:]
- #ファイル書き込み
- f = open(path,"w")
- f.write(data)
- f.close
- client.run(TOKEN)
Add Comment
Please, Sign In to add comment