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.

148 lines
4.4KB

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