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.

175 lines
5.0KB

  1. #!/usr/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. MIT License
  5. Copyright (c) 2017-2018 Roxanne Gibson
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12. The above copyright notice and this permission notice shall be included in all
  13. copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. SOFTWARE.
  21. """
  22. import time
  23. import logging
  24. import os.path
  25. import datetime
  26. import discord
  27. from discord.ext import commands
  28. import roxbot
  29. from roxbot import guild_settings as gs
  30. # REMEMBER TO UNCOMMENT THE GSS LINE, ROXIE
  31. # DO NOT UNCOMMENT GSS IF YOU ARE NOT ROXIE
  32. cogs = [
  33. "roxbot.cogs.admin",
  34. "roxbot.cogs.customcommands",
  35. "roxbot.cogs.fun",
  36. "roxbot.cogs.image",
  37. "roxbot.cogs.joinleave",
  38. "roxbot.cogs.nsfw",
  39. "roxbot.cogs.reddit",
  40. "roxbot.cogs.selfassign",
  41. "roxbot.cogs.trivia",
  42. "roxbot.cogs.twitch",
  43. "roxbot.cogs.util",
  44. "roxbot.cogs.voice",
  45. #"roxbot.cogs.gss"
  46. ]
  47. # Sets up Logging that discord.py does on its own
  48. logger = logging.getLogger('discord')
  49. logger.setLevel(logging.INFO)
  50. handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w')
  51. handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
  52. logger.addHandler(handler)
  53. bot = commands.Bot(
  54. command_prefix=roxbot.command_prefix,
  55. description=roxbot.__description__,
  56. owner_id=roxbot.owner,
  57. activity=discord.Game(name="v{}".format(roxbot.__version__), type=0),
  58. case_insensitive=True
  59. )
  60. @bot.event
  61. async def on_ready():
  62. # Load Roxbots inbuilt cogs and settings
  63. print("Loading Bot internals...")
  64. bot.load_extension("roxbot.system")
  65. print("system.py Loaded")
  66. bot.load_extension("roxbot.settings.settings")
  67. print("settings.py Loaded")
  68. bot.load_extension("roxbot.err_handle")
  69. print("err_handle.py Loaded")
  70. bot.load_extension("roxbot.logging")
  71. print("logging.py Loaded")
  72. print("")
  73. print("Discord.py version: " + discord.__version__)
  74. print("Client logged in\n")
  75. # Load Extension Cogs
  76. print("Cogs Loaded:")
  77. for cog in cogs:
  78. try:
  79. bot.load_extension(cog)
  80. print(cog.split(".")[2])
  81. except ImportError:
  82. print("{} FAILED TO LOAD. MISSING REQUIREMENTS".format(cog.split(".")[2]))
  83. print("")
  84. print("Servers I am currently in:")
  85. for server in bot.guilds:
  86. print(server)
  87. # this is so if we're added to a server while we're offline we deal with it
  88. try:
  89. gs.get(server)
  90. except KeyError:
  91. print("Server not found in servers.json - adding example config")
  92. gs.add_guild(server)
  93. print("")
  94. @bot.event
  95. async def on_guild_join(guild):
  96. gs.add_guild(guild)
  97. @bot.event
  98. async def on_guild_remove(guild):
  99. gs.remove_guild(guild)
  100. @bot.event
  101. async def on_message(message):
  102. """
  103. Checks if the user is blacklisted, if not, process the message for commands as usual.
  104. """
  105. if roxbot.blacklisted(message.author):
  106. return
  107. return await bot.process_commands(message)
  108. @bot.command()
  109. async def about(ctx):
  110. """
  111. Outputs info about RoxBot, showing up time, how to report issues, what settings where set in prefs.ini and credits.
  112. """
  113. owner = bot.get_user(roxbot.owner)
  114. em = discord.Embed(title="About Roxbot", colour=roxbot.EmbedColours.pink, description=roxbot.__description__)
  115. em.set_thumbnail(url=bot.user.avatar_url)
  116. em.add_field(name="Command Prefix", value=roxbot.command_prefix)
  117. em.add_field(name="Owner", value=str(owner))
  118. em.add_field(name="Owner ID", value=roxbot.owner)
  119. em.add_field(name="Bot Version", value=roxbot.__version__)
  120. em.add_field(name="Author", value=roxbot.__author__)
  121. em.add_field(name="Discord.py version", value=discord.__version__)
  122. em.set_footer(text="RoxBot is licensed under the MIT License")
  123. # Do time calc late in the command so that the time returned is closest to when the message is received
  124. uptimeflo = time.time() - start_time
  125. uptime = str(datetime.timedelta(seconds=uptimeflo))
  126. em.add_field(name="Current Uptime", value=str(uptime.split(".")[0]))
  127. return await ctx.channel.send(embed=em)
  128. if __name__ == "__main__":
  129. # Pre-Boot checks
  130. if not os.path.isfile("roxbot/settings/preferences.ini"):
  131. print(
  132. "PREFERENCE FILE MISSING. Something has gone wrong. Please make sure there is a file called 'preferences.ini' in the settings folder")
  133. exit(0)
  134. if not os.path.isfile("roxbot/settings/servers.json"):
  135. with open("roxbot/settings/servers.json", "w") as fp:
  136. fp.write("{}")
  137. start_time = time.time()
  138. bot.run(roxbot.token)