No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

151 líneas
4.6KB

  1. #!/usr/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. MIT License
  5. Copyright (c) 2017-2018 Roxanne Gibson
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12. The above copyright notice and this permission notice shall be included in all
  13. copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. SOFTWARE.
  21. """
  22. import time
  23. import logging
  24. import os.path
  25. import datetime
  26. import discord
  27. from discord.ext import commands
  28. import roxbot
  29. from roxbot import guild_settings as gs
  30. # Sets up Logging that discord.py does on its own
  31. logger = logging.getLogger('discord')
  32. logger.setLevel(logging.INFO)
  33. handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w')
  34. handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
  35. logger.addHandler(handler)
  36. bot = commands.Bot(
  37. command_prefix=roxbot.command_prefix,
  38. description=roxbot.__description__,
  39. owner_id=roxbot.owner,
  40. activity=discord.Game(name="v{}".format(roxbot.__version__), type=0),
  41. case_insensitive=True
  42. )
  43. @bot.event
  44. async def on_ready():
  45. # Load Roxbots inbuilt cogs and settings
  46. print("Loading Bot internals...")
  47. bot.load_extension("roxbot.system")
  48. print("system.py Loaded")
  49. bot.load_extension("roxbot.err_handle")
  50. print("err_handle.py Loaded")
  51. bot.load_extension("roxbot.logging")
  52. print("logging.py Loaded")
  53. print("")
  54. print("Discord.py version: " + discord.__version__)
  55. print("Client logged in\n")
  56. # Load Extension Cogs
  57. print("Cogs Loaded:")
  58. for cog in roxbot.cogs:
  59. try:
  60. bot.load_extension(cog)
  61. print(cog.split(".")[2])
  62. except ImportError:
  63. print("{} FAILED TO LOAD. MISSING REQUIREMENTS".format(cog.split(".")[2]))
  64. print("")
  65. # this is so if we're added to a server while we're offline we deal with it
  66. roxbot.guild_settings.error_check(bot.guilds, bot.cogs)
  67. print("Guilds I'm currently in:")
  68. for guild in bot.guilds:
  69. print(guild)
  70. print("")
  71. @bot.event
  72. async def on_guild_join(guild):
  73. gs.add_guild(guild, bot.cogs)
  74. @bot.event
  75. async def on_guild_remove(guild):
  76. gs.remove_guild(guild)
  77. @bot.event
  78. async def on_message(message):
  79. """
  80. Checks if the user is blacklisted, if not, process the message for commands as usual.
  81. """
  82. if roxbot.blacklisted(message.author):
  83. return
  84. return await bot.process_commands(message)
  85. @bot.command()
  86. async def about(ctx):
  87. """
  88. Outputs info about RoxBot, showing up time, how to report issues, what settings where set in prefs.ini and credits.
  89. """
  90. owner = bot.get_user(roxbot.owner)
  91. em = discord.Embed(title="About Roxbot", colour=roxbot.EmbedColours.pink, description=roxbot.__description__)
  92. em.set_thumbnail(url=bot.user.avatar_url)
  93. em.add_field(name="Command Prefix", value=roxbot.command_prefix)
  94. em.add_field(name="Owner", value=str(owner))
  95. em.add_field(name="Owner ID", value=roxbot.owner)
  96. em.add_field(name="Bot Version", value=roxbot.__version__)
  97. em.add_field(name="Author", value=roxbot.__author__)
  98. em.add_field(name="Discord.py version", value=discord.__version__)
  99. em.set_footer(text="RoxBot is licensed under the MIT License")
  100. # Do time calc late in the command so that the time returned is closest to when the message is received
  101. uptimeflo = time.time() - start_time
  102. uptime = str(datetime.timedelta(seconds=uptimeflo))
  103. em.add_field(name="Current Uptime", value=str(uptime.split(".")[0]))
  104. return await ctx.channel.send(embed=em)
  105. @commands.command(pass_context=False, hidden=True)
  106. async def settings():
  107. # This is to block any customcommand or command from being made with the same name.
  108. # This is to avoid conflicts with the internal settings system.
  109. raise commands.CommandNotFound()
  110. if __name__ == "__main__":
  111. # Pre-Boot checks
  112. if not os.path.isfile("roxbot/settings/preferences.ini"):
  113. print("PREFERENCE FILE MISSING. Please make sure there is a file called 'preferences.ini' in the settings folder")
  114. exit(0)
  115. start_time = time.time()
  116. bot.run(roxbot.token)