您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

115 行
3.4KB

  1. #!/usr/env python3
  2. import time
  3. import logging
  4. import os.path
  5. import datetime
  6. import discord
  7. from discord.ext import commands
  8. import roxbot
  9. from roxbot import guild_settings as gs
  10. # Sets up Logging that discord.py does on its own
  11. logger = logging.getLogger('discord')
  12. logger.setLevel(logging.INFO)
  13. handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w')
  14. handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
  15. logger.addHandler(handler)
  16. bot = commands.Bot(
  17. command_prefix=roxbot.command_prefix,
  18. description=roxbot.__description__,
  19. owner_id=roxbot.owner,
  20. activity=discord.Game(name="v{}".format(roxbot.__version__), type=0),
  21. case_insensitive=True
  22. )
  23. @bot.event
  24. async def on_ready():
  25. # Load Roxbots inbuilt cogs and settings
  26. bot.load_extension("roxbot.settings.settings")
  27. bot.load_extension("roxbot.err_handle")
  28. bot.load_extension("roxbot.logging")
  29. bot.load_extension("roxbot.system")
  30. bot.settings = gs.get_all(bot.guilds)
  31. print("Discord.py version: " + discord.__version__)
  32. print("Client logged in\n")
  33. # Load Extension Cogs
  34. print("Cogs Loaded:")
  35. for cog in roxbot.cogs:
  36. bot.load_extension(cog)
  37. print(cog.split(".")[2])
  38. print("")
  39. print("Servers I am currently in:")
  40. for server in bot.guilds:
  41. print(server)
  42. print("")
  43. # In the next two functions, I was gunna user bot.settings for something but I don't think it's possible.
  44. # So while I don't use it, the function still will do their jobs of adding and removing the settings.
  45. @bot.event
  46. async def on_guild_join(guild):
  47. gs.add_guild(guild)
  48. @bot.event
  49. async def on_guild_remove(guild):
  50. gs.remove_guild(guild)
  51. @bot.event
  52. async def on_message(message):
  53. """
  54. Checks if the user is blacklisted, if not, process the message for commands as usual.
  55. :param message:
  56. :return:
  57. """
  58. if roxbot.blacklisted(message.author):
  59. return
  60. return await bot.process_commands(message)
  61. @bot.command()
  62. async def about(ctx):
  63. """
  64. Outputs info about RoxBot, showing uptime, how to report issues, what settings where set in prefs.ini and credits.
  65. """
  66. owner = bot.get_user(roxbot.owner)
  67. em = discord.Embed(title="About Roxbot", colour=roxbot.EmbedColours.pink, description=roxbot.__description__)
  68. em.set_thumbnail(url=bot.user.avatar_url)
  69. em.add_field(name="Command Prefix", value=roxbot.command_prefix)
  70. em.add_field(name="Owner", value=str(owner))
  71. em.add_field(name="Owner ID", value=roxbot.owner)
  72. em.add_field(name="Bot Version", value=roxbot.__version__)
  73. em.add_field(name="Author", value=roxbot.__author__)
  74. em.add_field(name="Discord.py version", value=discord.__version__)
  75. em.set_footer(text="RoxBot is licensed under the MIT License")
  76. # Do time calc late in the command so that the time returned is closest to when the message is received
  77. uptimeflo = time.time() - start_time
  78. uptime = str(datetime.timedelta(seconds=uptimeflo))
  79. em.add_field(name="Current Uptime", value=str(uptime.split(".")[0]))
  80. return await ctx.channel.send(embed=em)
  81. if __name__ == "__main__":
  82. # Pre-Boot checks
  83. if not os.path.isfile("roxbot/settings/preferences.ini"):
  84. print(
  85. "PREFERENCE FILE MISSING. Something has gone wrong. Please make sure there is a file called 'preferences.ini' in the settings folder")
  86. exit(0)
  87. if not os.path.isfile("roxbot/settings/servers.json"):
  88. with open("roxbot/settings/servers.json", "w") as fp:
  89. fp.write("{}")
  90. start_time = time.time()
  91. bot.run(roxbot.token)