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.

181 lines
5.3KB

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