KiTTY, un bot Discord qui est un petit chat :) Il est basé sur une ancienne version du bot Red, sous Python 3.6 et qui a des fonctionnalités bien sympatiques !
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
此仓库已存档。您可以查看文件和克隆,但不能推送或创建工单/合并请求。

274 行
10KB

  1. import discord
  2. from discord.ext import commands
  3. from __main__ import send_cmd_help
  4. from bs4 import BeautifulSoup
  5. import requests
  6. import random
  7. import nekos
  8. nsfw_warning = "Go into a NSFW channel to use this command."
  9. class Nsfw:
  10. """Nsfw commands."""
  11. def __init__(self, bot):
  12. self.bot = bot
  13. self.session = self.bot.http.session
  14. @commands.group(pass_context=True)
  15. async def nsfw(self, ctx):
  16. """Nsfw Commands"""
  17. if ctx.invoked_subcommand is None:
  18. await send_cmd_help(ctx)
  19. @nsfw.command(no_pm=True, pass_context=True)
  20. async def yandere(self, ctx):
  21. """Random Image From Yandere"""
  22. channel_nsfw = await self.is_nsfw(ctx.message.channel)
  23. if not channel_nsfw:
  24. await self.bot.say(nsfw_warning)
  25. return
  26. try:
  27. query = ("https://yande.re/post/random")
  28. page = await self.session.get(query)
  29. page = await page.text()
  30. soup = BeautifulSoup(page, 'html.parser')
  31. image = soup.find(id="highres").get("href")
  32. await self.bot.say(image)
  33. except Exception as e:
  34. await self.bot.say(":x: **Error:** `{}`".format(e))
  35. @nsfw.command(no_pm=True, pass_context=True)
  36. async def konachan(self, ctx):
  37. """Random Image From Konachan"""
  38. channel_nsfw = await self.is_nsfw(ctx.message.channel)
  39. if not channel_nsfw:
  40. await self.bot.say(nsfw_warning)
  41. return
  42. try:
  43. query = ("https://konachan.com/post/random")
  44. page = await self.session.get(query)
  45. page = await page.text()
  46. soup = BeautifulSoup(page, 'html.parser')
  47. image = soup.find(id="highres").get("href")
  48. await self.bot.say(image)
  49. except Exception as e:
  50. await self.bot.say(":x: **Error:** `{}`".format(e))
  51. @nsfw.command(no_pm=True, pass_context=True)
  52. async def e621(self, ctx):
  53. """Random Image From e621"""
  54. channel_nsfw = await self.is_nsfw(ctx.message.channel)
  55. if not channel_nsfw:
  56. await self.bot.say(nsfw_warning)
  57. return
  58. try:
  59. query = ("https://e621.net/post/random")
  60. headers = {'User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0'}
  61. page = await self.session.get(query, headers=headers)
  62. page = await page.text()
  63. soup = BeautifulSoup(page, 'html.parser')
  64. image = soup.find(id="highres").get("href")
  65. await self.bot.say(image)
  66. except Exception as e:
  67. await self.bot.say(":x: **Error:** `{}`".format(e))
  68. print(e)
  69. @nsfw.command(no_pm=True, pass_context=True)
  70. async def rule34(self, ctx):
  71. """Random Image From rule34"""
  72. channel_nsfw = await self.is_nsfw(ctx.message.channel)
  73. if not channel_nsfw:
  74. await self.bot.say(nsfw_warning)
  75. return
  76. try:
  77. query = ("http://rule34.xxx/index.php?page=post&s=random")
  78. page = await self.session.get(query)
  79. page = await page.text()
  80. soup = BeautifulSoup(page, 'html.parser')
  81. image = soup.find(id="image").get("src")
  82. await self.bot.say(image)
  83. except Exception as e:
  84. await self.bot.say(":x: **Error:** `{}`".format(e))
  85. @nsfw.command(no_pm=True, pass_context=True)
  86. async def danbooru(self, ctx):
  87. """Random Image From Danbooru"""
  88. channel_nsfw = await self.is_nsfw(ctx.message.channel)
  89. if not channel_nsfw:
  90. await self.bot.say(nsfw_warning)
  91. return
  92. try:
  93. query = ("http://danbooru.donmai.us/posts/random")
  94. page = await self.session.get(query)
  95. page = await page.text()
  96. soup = BeautifulSoup(page, 'html.parser')
  97. image = soup.find(id="image").get("src")
  98. await self.bot.say(image)
  99. except Exception as e:
  100. await self.bot.say(":x: **Error:** `{}`".format(e))
  101. @nsfw.command(no_pm=True, pass_context=True)
  102. async def gelbooru(self, ctx):
  103. """Random Image From Gelbooru"""
  104. channel_nsfw = await self.is_nsfw(ctx.message.channel)
  105. if not channel_nsfw:
  106. await self.bot.say(nsfw_warning)
  107. return
  108. try:
  109. query = ("http://www.gelbooru.com/index.php?page=post&s=random")
  110. page = await self.session.get(query)
  111. page = await page.text()
  112. soup = BeautifulSoup(page, 'html.parser')
  113. image = soup.find(id="image").get("src")
  114. await self.bot.say(image)
  115. except Exception as e:
  116. await self.bot.say(":x: **Error:** `{}`".format(e))
  117. @nsfw.command(no_pm=True, pass_context=True)
  118. async def tbib(self, ctx):
  119. """Random Image From DrunkenPumken"""
  120. channel_nsfw = await self.is_nsfw(ctx.message.channel)
  121. if not channel_nsfw:
  122. await self.bot.say(nsfw_warning)
  123. return
  124. try:
  125. query = ("http://www.tbib.org/index.php?page=post&s=random")
  126. page = await self.session.get(query)
  127. page = await page.text()
  128. soup = BeautifulSoup(page, 'html.parser')
  129. image = soup.find(id="image").get("src")
  130. await self.bot.say("http:" + image)
  131. except Exception as e:
  132. await self.bot.say(":x: **Error:** `{}`".format(e))
  133. @nsfw.command(no_pm=True, pass_context=True)
  134. async def xbooru(self, ctx):
  135. """Random Image From Xbooru"""
  136. channel_nsfw = await self.is_nsfw(ctx.message.channel)
  137. if not channel_nsfw:
  138. await self.bot.say(nsfw_warning)
  139. return
  140. try:
  141. query = ("http://xbooru.com/index.php?page=post&s=random")
  142. page = await self.session.get(query)
  143. page = await page.text()
  144. soup = BeautifulSoup(page, 'html.parser')
  145. image = soup.find(id="image").get("src")
  146. await self.bot.say(image)
  147. except Exception as e:
  148. await self.bot.say(":x: **Error:** `{}`".format(e))
  149. @nsfw.command(no_pm=True, pass_context=True)
  150. async def furrybooru(self, ctx):
  151. """Random Image From Furrybooru"""
  152. channel_nsfw = await self.is_nsfw(ctx.message.channel)
  153. if not channel_nsfw:
  154. await self.bot.say(nsfw_warning)
  155. return
  156. try:
  157. query = ("http://furry.booru.org/index.php?page=post&s=random")
  158. page = await self.session.get(query)
  159. page = await page.text()
  160. soup = BeautifulSoup(page, 'html.parser')
  161. image = soup.find(id="image").get("src")
  162. await self.bot.say(image)
  163. except Exception as e:
  164. await self.bot.say(":x: **Error:** `{}`".format(e))
  165. @nsfw.command(no_pm=True, pass_context=True)
  166. async def drunkenpumken(self, ctx):
  167. """Random Image From DrunkenPumken"""
  168. channel_nsfw = await self.is_nsfw(ctx.message.channel)
  169. if not channel_nsfw:
  170. await self.bot.say(nsfw_warning)
  171. return
  172. try:
  173. query = ("http://drunkenpumken.booru.org/index.php?page=post&s=random")
  174. page = await self.session.get(query)
  175. page = await page.text()
  176. soup = BeautifulSoup(page, 'html.parser')
  177. image = soup.find(id="image").get("src")
  178. await self.bot.say(image)
  179. except Exception as e:
  180. await self.bot.say(":x: **Error:** `{}`".format(e))
  181. @nsfw.command(no_pm=True, pass_context=True)
  182. async def lolibooru(self, ctx):
  183. """Random Image From Lolibooru"""
  184. channel_nsfw = await self.is_nsfw(ctx.message.channel)
  185. if not channel_nsfw:
  186. await self.bot.say(nsfw_warning)
  187. return
  188. try:
  189. query = ("https://lolibooru.moe/post/random/")
  190. page = await self.session.get(query)
  191. page = await page.text()
  192. soup = BeautifulSoup(page, 'html.parser')
  193. image = soup.find(id="image").get("src")
  194. image = image.replace(' ', '%20')
  195. await self.bot.say(image)
  196. except Exception as e:
  197. await self.bot.say(":x: **Error:** `{}`".format(e))
  198. @nsfw.command(pass_context=True, no_pm=True)
  199. async def ysearch(self, ctx, *tags: str):
  200. """Search Yandere With A Tag"""
  201. channel_nsfw = await self.is_nsfw(ctx.message.channel)
  202. if not channel_nsfw:
  203. await self.bot.say(nsfw_warning)
  204. return
  205. if tags == ():
  206. await self.bot.say(":warning: Tags are missing.")
  207. else:
  208. try:
  209. tags = ("+").join(tags)
  210. query = ("https://yande.re/post.json?limit=42&tags=" + tags)
  211. page = await self.session.get(query)
  212. json = await page.json()
  213. if json != []:
  214. await self.bot.say(random.choice(json)['jpeg_url'])
  215. else:
  216. await self.bot.say(":warning: Yande.re has no images for requested tags.")
  217. except Exception as e:
  218. await self.bot.say(":x: `{}`".format(e))
  219. @commands.command(pass_context=True, no_pm=True)
  220. async def neko(self, ctx):
  221. """A random neko image from nekos.py"""
  222. channel_nsfw = await self.is_nsfw(ctx.message.channel)
  223. if not channel_nsfw:
  224. await self.bot.say(nsfw_warning)
  225. return
  226. try:
  227. await self.bot.say(nekos.img('neko'))
  228. except Exception as e:
  229. await self.bot.say(":x: `{}`".format(e))
  230. @commands.command(pass_context=True, no_pm=True)
  231. async def yuri(self, ctx):
  232. """A random neko image from nekos.py"""
  233. channel_nsfw = await self.is_nsfw(ctx.message.channel)
  234. if not channel_nsfw:
  235. await self.bot.say(nsfw_warning)
  236. return
  237. try:
  238. await self.bot.say(nekos.img('yuri'))
  239. except Exception as e:
  240. await self.bot.say(":x: `{}`".format(e))
  241. async def is_nsfw(self, channel: discord.Channel):
  242. try:
  243. _gid = channel.server.id
  244. except AttributeError:
  245. return False
  246. data = await self.bot.http.request(
  247. discord.http.Route(
  248. 'GET', '/guilds/{guild_id}/channels', guild_id=_gid))
  249. channeldata = [d for d in data if d['id'] == channel.id][0]
  250. return channeldata['nsfw']
  251. def setup(bot):
  252. n = Nsfw(bot)
  253. bot.add_cog(n)