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.

185 lines
5.5KB

  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 datetime
  25. import logging
  26. import time
  27. import traceback
  28. import discord
  29. from discord.ext import commands
  30. import roxbot
  31. from roxbot import guild_settings as gs
  32. from roxbot import core
  33. class term:
  34. HEADER = '\033[95m'
  35. OKBLUE = '\033[94m'
  36. OKGREEN = '\033[92m'
  37. WARNING = '\033[93m'
  38. FAIL = '\033[91m'
  39. ENDC = '\033[0m'
  40. BOLD = '\033[1m'
  41. UNDERLINE = '\033[4m'
  42. fHEADER = HEADER + "{}" + ENDC
  43. fOKBLUE = OKBLUE + "{}" + ENDC
  44. fOKGREEN = OKGREEN + "{}" + ENDC
  45. fWARNING = WARNING + "{}" + ENDC
  46. fFAIL = FAIL + "{}" + ENDC
  47. fBOLD = BOLD + "{}" + ENDC
  48. fUNDERLINE = UNDERLINE + "{}" + ENDC
  49. seperator = "================================"
  50. title = """ ____ _ _
  51. | _ \ _____ _| |__ ___ | |_
  52. | |_) / _ \ \/ / '_ \ / _ \| __|
  53. | _ < (_) > <| |_) | (_) | |_
  54. |_| \_\___/_/\_\_.__/ \___/ \__|
  55. """
  56. # Sets up Logging
  57. #discord_logger = logging.getLogger('discord')
  58. #discord_logger.setLevel(logging.INFO)
  59. #discord_logger.addHandler(roxbot.handler)
  60. bot = core.Roxbot(
  61. command_prefix=roxbot.command_prefix,
  62. description=roxbot.__description__,
  63. owner_id=roxbot.owner,
  64. activity=discord.Game(name="v{}".format(roxbot.__version__), type=0),
  65. case_insensitive=True
  66. )
  67. @bot.event
  68. async def on_ready():
  69. print("Logged in as: {}".format(term.fOKGREEN.format(str(bot.user))), end="\n\n")
  70. # this is so if we're added to a server while we're offline we deal with it
  71. roxbot.guild_settings.error_check(bot.guilds, bot.cogs)
  72. print("Guilds in: [{}]".format(len(bot.guilds)))
  73. for guild in bot.guilds:
  74. print(guild)
  75. @bot.event
  76. async def on_guild_join(guild):
  77. gs.add_guild(guild, bot.cogs)
  78. @bot.event
  79. async def on_guild_remove(guild):
  80. gs.remove_guild(guild)
  81. @bot.event
  82. async def on_error(event, *args, **kwargs):
  83. if roxbot.dev_mode:
  84. traceback.print_exc()
  85. else:
  86. logging.exception(event)
  87. @bot.check
  88. def check_blacklist(ctx):
  89. """Adds global check to the bot to check for a user being blacklisted."""
  90. return not bot.blacklisted(ctx.author)
  91. @bot.command()
  92. async def about(ctx):
  93. """
  94. Outputs info about RoxBot, showing up time, how to report issues, contents of roxbot.conf and credits.
  95. """
  96. owner = bot.get_user(roxbot.owner)
  97. em = discord.Embed(title="About Roxbot", colour=roxbot.EmbedColours.pink, description=roxbot.__description__)
  98. em.set_thumbnail(url=bot.user.avatar_url)
  99. em.add_field(name="Bot Version", value=roxbot.__version__)
  100. em.add_field(name="Discord.py version", value=discord.__version__)
  101. em.add_field(name="Owner", value=str(owner))
  102. em.add_field(name="Owner ID", value=roxbot.owner)
  103. em.add_field(name="Command Prefix", value=roxbot.command_prefix)
  104. em.add_field(name="Backup Enabled", value=roxbot.backup_enabled)
  105. if roxbot.backup_enabled:
  106. em.add_field(name="Backup Rate", value="{} Minutes".format(int(roxbot.backup_rate/60)))
  107. em.add_field(name="Author", value=roxbot.__author__)
  108. # Do time calc late in the command so that the time returned is closest to when the message is received
  109. uptimeflo = time.time() - start_time
  110. uptime = str(datetime.timedelta(seconds=uptimeflo))
  111. em.add_field(name="Current Uptime", value=str(uptime.split(".")[0]))
  112. em.set_footer(text="RoxBot is licensed under the MIT License")
  113. return await ctx.channel.send(embed=em)
  114. @commands.command(pass_context=False, hidden=True)
  115. async def settings():
  116. # This is to block any customcommand or command from being made with the same name.
  117. # This is to avoid conflicts with the internal settings system.
  118. raise commands.CommandNotFound("settings")
  119. if __name__ == "__main__":
  120. start_time = time.time()
  121. print(term.fHEADER.format(term.fBOLD.format(term.title)))
  122. print("Roxbot version: " + term.fOKBLUE.format(roxbot.__version__))
  123. print("Discord.py version: " + term.fOKBLUE.format(discord.__version__))
  124. print(term.seperator)
  125. print("Loading core...", end="\r")
  126. bot.load_extension("roxbot.core")
  127. print("Loaded core.py")
  128. print(term.seperator)
  129. # Load Extension Cogs
  130. print("Cogs Loaded:")
  131. for cog in roxbot.cogs:
  132. try:
  133. bot.load_extension(cog)
  134. print(cog.split(".")[2])
  135. except ImportError:
  136. print("{} FAILED TO LOAD. MISSING REQUIREMENTS".format(cog.split(".")[2]))
  137. # This commits all the entities defined by the cogs. These are loaded above. Do Not Remove.
  138. bot.loop.create_task(roxbot.db.populate_db(bot))
  139. print(term.seperator)
  140. print("Client logging in...", end="\r")
  141. bot.run(roxbot.token)