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.

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