tsutitire2

Untitled

Jul 8th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Wed Jul 8 23:23:15 2020
  4.  
  5. @author: tsutitire
  6. """
  7. import discord
  8. import random
  9. client = discord.Client()
  10. TOKEN = 'Your Token'
  11.  
  12. indalpha = 0
  13.  
  14. @client.event
  15. async def on_ready():
  16. #コンソールにメッセージを送信
  17. print('loggined!')
  18. print("haraseu bot")
  19.  
  20. #挨拶
  21. channel = client.get_channel(Your talking channel ID)
  22. await channel.send("むにゃ...おはらせう!")
  23.  
  24. #アクティビティの設定
  25. activity = discord.Game(name="Help:haraseu/help")
  26. await client.change_presence(status=discord.Status.idle, activity=activity)
  27.  
  28.  
  29.  
  30. @client.event
  31. async def on_message(message):
  32. #ボットはお帰り下さい
  33. if message.author.bot:
  34. return
  35. global indalpha
  36.  
  37. #ファイル読み込み
  38. path = 'haraseu.txt'
  39. f = open(path,"r")
  40. words = f.read()
  41. words = str(words)
  42. f.close()
  43.  
  44. #変数初期化
  45. indalpha = 0
  46. #ランダム=>抜きだし
  47. rnd = random.randrange(words.count(";") / 2 + 1)
  48. for dummy in range((rnd * 2 - 2)):
  49. indalpha = words.find(";",indalpha + 1)
  50. indbeta = words.find(";",indalpha + 1)
  51. data = words[indalpha + 1:indbeta]
  52. #送信
  53. await message.channel.send(data)
  54.  
  55. #ヘルプ
  56. if message.content.startswith("haraseu/help"):
  57. embed = discord.Embed(title="The help of HARASEU",description="はらせうBOTの使い方せう" )
  58. #embed.set_image(url="https://b.imgef.com/POuypFI.png")
  59. embed.add_field(name="haraseu/learn",value="入力された文字を覚えるせう セミコロンは使わないでほしいせう(e.g. haraseu/learn はらせう)")
  60. embed.add_field(name="haraseu/remove",value="IDに対応する言葉を削除するせう (e.g. haraseu/remove 234)")
  61. embed.add_field(name="haraseu/list",value="文字のリストを出力するせう (e.g. haraseu/list)")
  62.  
  63. #送信
  64. await message.channel.send(embed=embed)
  65.  
  66. #学習
  67. if message.content.startswith("haraseu/learn"):
  68. #ファイル読み込み
  69. path = 'haraseu.txt'
  70. f = open(path,"r")
  71. words = f.read()
  72. f.close()
  73. #ファイル書き込み
  74. f = open(path,"w")
  75. #--データを変数へ
  76. data = str(message.content[14:])
  77. #--セミコロンはだめです
  78. if data.find(";") != -1:
  79. await message.channel.send("セミコロンつかうとエラー起きちゃうからやめて欲しいせう~")
  80. return
  81. #--書き込みデータ作成
  82. data2 = str(words) + ";" + str(data) + ";"
  83. data2 = str(data2)
  84. #--ID作成
  85. yid = data2.count(";")
  86. yid = yid/2
  87. #--書き込み
  88. f.write(data2)
  89. f.close
  90. await message.channel.send("アップロード完了だせう! ID:" + str(yid))
  91.  
  92. #リスト
  93. if message.content.startswith("haraseu/list"):
  94. #中身取得だせう
  95. path = 'haraseu.txt'
  96. f = open(path,"r")
  97. words = f.read()
  98. f.close
  99.  
  100. #送信
  101. await message.channel.send(str(words))
  102.  
  103. #削除(ごり押し)
  104. if message.content.startswith("haraseu/remove"):
  105. #中身取得だせう
  106. path = 'haraseu.txt'
  107. f = open(path,"r")
  108. words = f.read()
  109. f.close
  110.  
  111. #変数リセット
  112. indalpha = 0
  113. #ID=>位置変換
  114. for dummy in range((int(message.content[15:]) * 2 - 2)):
  115. indalpha = words.find(";",indalpha + 1)
  116. indbeta = words.find(";",indalpha + 1)
  117. indalpha = indalpha - 1
  118. #データ作成
  119. data = words[:indalpha] + words[indbeta:]
  120.  
  121. #ファイル書き込み
  122. f = open(path,"w")
  123. f.write(data)
  124. f.close
  125.  
  126.  
  127. client.run(TOKEN)
Add Comment
Please, Sign In to add comment