Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

173 lines
4.9KB

  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. 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 = core.Roxbot(
  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. print("Guilds in: [{}]".format(len(bot.guilds)))
  70. for guild in bot.guilds:
  71. print(guild)
  72. @bot.event
  73. async def on_guild_join(guild):
  74. db.populate_single_settings(bot)
  75. @bot.event
  76. async def on_guild_remove(guild):
  77. db.delete_single_settings(guild)
  78. @bot.event
  79. async def on_error(event, *args, **kwargs):
  80. if roxbot.dev_mode:
  81. traceback.print_exc()
  82. else:
  83. logging.exception(event)
  84. @bot.check
  85. def check_blacklist(ctx):
  86. """Adds global check to the bot to check for a user being blacklisted."""
  87. return not bot.blacklisted(ctx.author)
  88. @bot.command()
  89. async def about(ctx):
  90. """
  91. Outputs info about RoxBot, showing up time, how to report issues, contents of roxbot.conf and credits.
  92. """
  93. owner = bot.get_user(roxbot.owner)
  94. em = discord.Embed(title="About Roxbot", colour=roxbot.EmbedColours.pink, description=roxbot.__description__)
  95. em.set_thumbnail(url=bot.user.avatar_url)
  96. em.add_field(name="Bot Version", value=roxbot.__version__)
  97. em.add_field(name="Discord.py version", value=discord.__version__)
  98. em.add_field(name="Owner", value=str(owner))
  99. em.add_field(name="Owner ID", value=roxbot.owner)
  100. em.add_field(name="Command Prefix", value=roxbot.command_prefix)
  101. em.add_field(name="Backup Enabled", value=roxbot.backup_enabled)
  102. if roxbot.backup_enabled:
  103. em.add_field(name="Backup Rate", value="{} Minutes".format(int(roxbot.backup_rate/60)))
  104. em.add_field(name="Author", value=roxbot.__author__)
  105. # Do time calc late in the command so that the time returned is closest to when the message is received
  106. uptimeflo = time.time() - start_time
  107. uptime = str(datetime.timedelta(seconds=uptimeflo))
  108. em.add_field(name="Current Uptime", value=str(uptime.split(".")[0]))
  109. em.set_footer(text="RoxBot is licensed under the MIT License")
  110. return await ctx.channel.send(embed=em)
  111. if __name__ == "__main__":
  112. start_time = time.time()
  113. print(term.fHEADER.format(term.fBOLD.format(term.title)))
  114. print("Roxbot version: " + term.fOKBLUE.format(roxbot.__version__))
  115. print("Discord.py version: " + term.fOKBLUE.format(discord.__version__))
  116. print(term.seperator)
  117. print("Loading core...", end="\r")
  118. bot.load_extension("roxbot.core")
  119. print("Loaded core.py")
  120. print(term.seperator)
  121. # Load Extension Cogs
  122. print("Cogs Loaded:")
  123. for cog in roxbot.cogs:
  124. try:
  125. bot.load_extension(cog)
  126. print(cog.split(".")[2])
  127. except ImportError:
  128. print("{} FAILED TO LOAD. MISSING REQUIREMENTS".format(cog.split(".")[2]))
  129. bot.loop.create_task(db.populate_db(bot))
  130. print(term.seperator)
  131. print("Client logging in...", end="\r")
  132. bot.run(roxbot.token)