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.

168 lines
5.1KB

  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. import roxbot
  30. from roxbot import db
  31. from roxbot import core
  32. from roxbot.scripts import JSONtoDB
  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. print("Guilds in: [{}]".format(len(bot.guilds)))
  71. for guild in bot.guilds:
  72. print(guild)
  73. roxbot.scripts.JSONtoDB.check_convert(bot.guilds)
  74. @bot.event
  75. async def on_guild_join(guild):
  76. db.populate_single_settings(bot)
  77. @bot.event
  78. async def on_guild_remove(guild):
  79. db.delete_single_settings(guild)
  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 bot.blacklisted(ctx.author)
  84. @bot.command()
  85. async def about(ctx):
  86. """
  87. Outputs info about RoxBot, showing up time, how to report issues, contents of roxbot.conf 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="Bot Version", value=roxbot.__version__)
  93. em.add_field(name="Discord.py version", value=discord.__version__)
  94. em.add_field(name="Owner", value=str(owner))
  95. em.add_field(name="Owner ID", value=roxbot.owner)
  96. em.add_field(name="Command Prefix", value=roxbot.command_prefix)
  97. em.add_field(name="Backup Enabled", value=roxbot.backup_enabled)
  98. if roxbot.backup_enabled:
  99. em.add_field(name="Backup Rate", value="{} Minutes".format(int(roxbot.backup_rate/60)))
  100. em.add_field(name="Author", value=roxbot.__author__)
  101. # Do time calc late in the command so that the time returned is closest to when the message is received
  102. uptimeflo = time.time() - start_time
  103. uptime = str(datetime.timedelta(seconds=uptimeflo))
  104. em.add_field(name="Current Uptime", value=str(uptime.split(".")[0]))
  105. em.set_footer(text="RoxBot is licensed under the MIT License")
  106. return await ctx.channel.send(embed=em)
  107. if __name__ == "__main__":
  108. start_time = time.time()
  109. print(term.fHEADER.format(term.fBOLD.format(term.title)))
  110. print("Roxbot version: " + term.fOKBLUE.format(roxbot.__version__))
  111. print("Discord.py version: " + term.fOKBLUE.format(discord.__version__))
  112. print(term.seperator)
  113. print("Loading core...", end="\r")
  114. bot.load_extension("roxbot.core")
  115. print("Loaded core.py")
  116. print(term.seperator)
  117. # Load Extension Cogs
  118. print("Cogs Loaded:")
  119. for cog in roxbot.cog_list:
  120. try:
  121. bot.load_extension(cog)
  122. print(cog.split(".")[2])
  123. except ImportError:
  124. print("{} FAILED TO LOAD. MISSING REQUIREMENTS".format(cog.split(".")[2]))
  125. bot.loop.create_task(db.populate_db(bot))
  126. print(term.seperator)
  127. print("Client logging in...", end="\r")
  128. bot.run(roxbot.token)