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 !
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

272 lines
11KB

  1. import discord
  2. from discord.ext import commands
  3. from cogs.utils.dataIO import dataIO
  4. from .utils import checks
  5. from __main__ import send_cmd_help
  6. # Sys
  7. import asyncio
  8. import aiohttp
  9. import time
  10. import random
  11. import os
  12. import sys
  13. DIR_DATA = "data/oboobs"
  14. SETTINGS = DIR_DATA+"/settings.json"
  15. DEFAULT = {"nsfw_channels": ["133251234164375552"], "invert" : False, "nsfw_msg": True, "last_update": 0, "ama_boobs": 10548, "ama_ass": 4542}# Red's testing chan. nsfw content off by default.
  16. #API info:
  17. #example: "/boobs/10/20/rank/" - get 20 boobs elements, start from 10th ordered by rank; noise: "/noise/{count=1; sql limit}/",
  18. #example: "/noise/50/" - get 50 random noise elements; model search: "/boobs/model/{model; sql ilike}/",
  19. #example: "/boobs/model/something/" - get all boobs elements, where model name contains "something", ordered by id; author search: "/boobs/author/{author; sql ilike}/",
  20. #example: "/boobs/author/something/" - get all boobs elements, where author name contains "something", ordered by id; get boobs by id: "/boobs/get/{id=0}/",
  21. #example: "/boobs/get/6202/" - get boobs element with id 6202; get boobs count: "/boobs/count/"; get noise count: "/noise/count/"; vote for boobs: "/boobs/vote/{id=0}/{operation=plus;[plus,minus]}/",
  22. #example: "/boobs/vote/6202/minus/" - negative vote for boobs with id 6202; vote for noise: "/noise/vote/{id=0}/{operation=plus;[plus,minus]}/",
  23. #example: "/noise/vote/57/minus/" - negative vote for noise with id 57;
  24. #example: "/butts/10/20/rank/" - get 20 butts elements, start from 10th ordered by rank; noise: "/noise/{count=1; sql limit}/",
  25. #example: "/noise/50/" - get 50 random noise elements; model search: "/butts/model/{model; sql ilike}/",
  26. #example: "/butts/model/something/" - get all butts elements, where model name contains "something", ordered by id; author search: "/butts/author/{author; sql ilike}/",
  27. #example: "/butts/author/something/" - get all butts elements, where author name contains "something", ordered by id; get butts by id: "/butts/get/{id=0}/",
  28. #example: "/butts/get/6202/" - get butts element with id 6202; get butts count: "/butts/count/"; get noise count: "/noise/count/"; vote for butts: "/butts/vote/{id=0}/{operation=plus;[plus,minus]}/",
  29. #example: "/butts/vote/6202/minus/" - negative vote for butts with id 6202; vote for noise: "/noise/vote/{id=0}/{operation=plus;[plus,minus]}/",
  30. #example: "/noise/vote/57/minus/" - negative vote for noise with id 57;
  31. class oboobs:
  32. """The oboobs/obutts.ru NSFW pictures of nature cog.
  33. https://github.com/Canule/Mash-Cogs
  34. """
  35. def __init__(self, bot):
  36. self.bot = bot
  37. self.settings = dataIO.load_json(SETTINGS)
  38. @commands.group(name="oboobs", pass_context=True)
  39. async def _oboobs(self, ctx):
  40. """The oboobs/obutts.ru pictures of nature cog."""
  41. if ctx.invoked_subcommand is None:
  42. await send_cmd_help(ctx)
  43. return
  44. # Boobs
  45. @commands.command(pass_context=True, no_pm=False)
  46. async def boobs(self, ctx):
  47. """Shows some boobs."""
  48. author = ctx.message.author
  49. dis_nsfw = None
  50. for a in self.settings["nsfw_channels"]:
  51. if a == ctx.message.channel.id:
  52. if self.settings["invert"]:
  53. dis_nsfw = False
  54. else:
  55. dis_nsfw = True
  56. break
  57. if dis_nsfw is None and not self.settings["invert"]:
  58. dis_nsfw = False
  59. else:
  60. dis_nsfw = True
  61. try:
  62. rdm = random.randint(0, self.settings["ama_boobs"])
  63. search = ("http://api.oboobs.ru/boobs/{}".format(rdm))
  64. async with aiohttp.get(search) as r:
  65. result = await r.json()
  66. boob = random.choice(result)
  67. boob = "http://media.oboobs.ru/{}".format(boob["preview"])
  68. except Exception as e:
  69. await self.bot.reply("Error getting results.")
  70. return
  71. if not dis_nsfw:
  72. await self.bot.say("{}".format(boob))
  73. else:
  74. await self.bot.send_message(ctx.message.author, "{}".format(boob))
  75. if self.settings["nsfw_msg"]:
  76. await self.bot.reply("nsfw content is not allowed in this channel, instead I have send you a DM.")
  77. # Ass
  78. @commands.command(pass_context=True, no_pm=False)
  79. async def ass(self, ctx):
  80. """Shows some ass."""
  81. author = ctx.message.author
  82. dis_nsfw = None
  83. for a in self.settings["nsfw_channels"]:
  84. if a == ctx.message.channel.id:
  85. if self.settings["invert"]:
  86. dis_nsfw = False
  87. else:
  88. dis_nsfw = True
  89. break
  90. if dis_nsfw is None and not self.settings["invert"]:
  91. dis_nsfw = False
  92. else:
  93. dis_nsfw = True
  94. try:
  95. rdm = random.randint(0, self.settings["ama_ass"])
  96. search = ("http://api.obutts.ru/butts/{}".format(rdm))
  97. async with aiohttp.get(search) as r:
  98. result = await r.json()
  99. ass = random.choice(result)
  100. ass = "http://media.obutts.ru/{}".format(ass["preview"])
  101. except Exception as e:
  102. await self.bot.reply("Error getting results.")
  103. return
  104. if not dis_nsfw:
  105. await self.bot.say("{}".format(ass))
  106. else:
  107. await self.bot.send_message(ctx.message.author, "{}".format(ass))
  108. if self.settings["nsfw_msg"]:
  109. await self.bot.reply("nsfw content is not allowed in this channel, instead I have send you a DM.")
  110. @checks.admin_or_permissions(manage_server=True)
  111. @_oboobs.command(pass_context=True, no_pm=True)
  112. async def nsfw(self, ctx):
  113. """Toggle oboobs nswf for this channel on/off.
  114. Admin/owner restricted."""
  115. nsfwChan = None
  116. # Reset nsfw.
  117. for a in self.settings["nsfw_channels"]:
  118. if a == ctx.message.channel.id:
  119. nsfwChan = True
  120. self.settings["nsfw_channels"].remove(a)
  121. await self.bot.reply("nsfw ON")
  122. break
  123. # Set nsfw.
  124. if not nsfwChan:
  125. if ctx.message.channel not in self.settings["nsfw_channels"]:
  126. self.settings["nsfw_channels"].append(ctx.message.channel.id)
  127. await self.bot.reply("nsfw OFF")
  128. dataIO.save_json(SETTINGS, self.settings)
  129. @checks.admin_or_permissions(manage_server=True)
  130. @_oboobs.command(pass_context=True, no_pm=True)
  131. async def invert(self, ctx):
  132. """Invert nsfw blacklist to whitlist
  133. Admin/owner restricted."""
  134. if not self.settings["invert"]:
  135. self.settings["invert"] = True
  136. await self.bot.reply("The nsfw list for all servers is now: inverted.")
  137. elif self.settings["invert"]:
  138. self.settings["invert"] = False
  139. await self.bot.reply("The nsfw list for all servers is now: default(blacklist)")
  140. dataIO.save_json(SETTINGS, self.settings)
  141. @checks.admin_or_permissions(manage_server=True)
  142. @_oboobs.command(pass_context=True, no_pm=True)
  143. async def togglemsg(self, ctx):
  144. """Enable/Disable the oboobs nswf not allowed message
  145. Admin/owner restricted."""
  146. # Toggle
  147. if self.settings["nsfw_msg"]:
  148. self.settings["nsfw_msg"] = False
  149. await self.bot.reply("DM nsfw channel msg is now: Disabled.`")
  150. elif not self.settings["nsfw_msg"]:
  151. self.settings["nsfw_msg"] = True
  152. await self.bot.reply("DM nsfw channel msg is now: Enabled.")
  153. dataIO.save_json(SETTINGS, self.settings)
  154. async def boob_knowlegde():
  155. # KISS
  156. settings = dataIO.load_json(SETTINGS)
  157. now = round(time.time())
  158. interval = 86400*2
  159. if now >= settings["last_update"]+interval:
  160. settings["last_update"] = now
  161. dataIO.save_json(SETTINGS, settings)
  162. else:
  163. return
  164. async def search(url, curr):
  165. search = ("{}{}".format(url, curr))
  166. async with aiohttp.get(search) as r:
  167. result = await r.json()
  168. return result
  169. # Upadate boobs len
  170. print("Updating amount of boobs...")
  171. curr_boobs = settings["ama_boobs"]
  172. url = "http://api.oboobs.ru/boobs/"
  173. done = False
  174. reachable = curr_boobs
  175. step = 50
  176. while not done:
  177. q = reachable+step
  178. #print("Searching for boobs:", q)
  179. res = await search(url, q)
  180. if res != []:
  181. reachable = q
  182. res_dc = await search(url, q+1)
  183. if res_dc == []:
  184. settings["ama_boobs"] = reachable
  185. dataIO.save_json(SETTINGS, settings)
  186. break
  187. else:
  188. await asyncio.sleep(2.5) # Trying to be a bit gentle for the api.
  189. continue
  190. elif res == []:
  191. step = round(step/2)
  192. if step <= 1:
  193. settings["ama_boobs"] = curr_boobs
  194. done = True
  195. await asyncio.sleep(2.5)
  196. print("Total amount of boobs:", settings["ama_boobs"])
  197. # Upadate ass len
  198. print("Updating amount of ass...")
  199. curr_ass = settings["ama_ass"]
  200. url = "http://api.obutts.ru/butts/"
  201. done = False
  202. reachable = curr_ass
  203. step = 50
  204. while not done:
  205. q = reachable+step
  206. #print("Searching for ass:", q)
  207. res = await search(url, q)
  208. if res != []:
  209. reachable = q
  210. res_dc = await search(url, q+1)
  211. if res_dc == []:
  212. settings["ama_ass"] = reachable
  213. dataIO.save_json(SETTINGS, settings)
  214. break
  215. else:
  216. await asyncio.sleep(2.5)
  217. continue
  218. elif res == []:
  219. step = round(step/2)
  220. if step <= 1:
  221. settings["ama_ass"] = curr_ass
  222. done = True
  223. await asyncio.sleep(2.5)
  224. print("Total amount of ass:", settings["ama_ass"])
  225. def check_folders():
  226. if not os.path.exists(DIR_DATA):
  227. print("Creating data/oboobs folder...")
  228. os.makedirs(DIR_DATA)
  229. def check_files():
  230. if not os.path.isfile(SETTINGS):
  231. print("Creating default boobs ass settings.json...")
  232. dataIO.save_json(SETTINGS, DEFAULT)
  233. else: # Key consistency check
  234. try:
  235. current = dataIO.load_json(SETTINGS)
  236. except JSONDecodeError:
  237. dataIO.save_json(SETTINGS, DEFAULT)
  238. current = dataIO.load_json(SETTINGS)
  239. if current.keys() != DEFAULT.keys():
  240. for key in DEFAULT.keys():
  241. if key not in current.keys():
  242. current[key] = DEFAULT[key]
  243. print( "Adding " + str(key) + " field to boobs settings.json")
  244. dataIO.save_json(SETTINGS, DEFAULT)
  245. def setup(bot):
  246. check_folders()
  247. check_files()
  248. bot.add_cog(oboobs(bot))
  249. bot.loop.create_task(oboobs.boob_knowlegde())