TerrificTable55

Untitled

May 23rd, 2022
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. from multiprocessing.connection import wait
  2. from discord.ext import commands
  3. import time
  4.  
  5. client = commands.Bot(command_prefix='>')
  6. users = {}
  7. command_channel = "main"
  8. channelID = None
  9. token = "OTc1MTI0NjA0MzYyMzA5Njgy.G_yXrN._mjATRjlrPxFwmzKTw1rUbDFTD4P-2C67UGOBY" # <-- TOKEN HERE
  10.  
  11.  
  12. async def log(msg):
  13. date = time.strftime("%d/%m/%Y | %H:%M:%S")
  14. log_msg = "[\033[90m{}\033[0m] \033[95m{}\033[96m ({})\033[0m: {}".format(date, msg.author, users[msg.author.name], msg.content.replace('\n', '\\n'))
  15.  
  16. # log message and date in console and log file
  17. print(log_msg)
  18. with open(f"./bot.{time.strftime('%d-%m')}.log", "a") as f:
  19. f.write(log_msg + "\n")
  20.  
  21. # post message and date in log channel
  22. if channelID:
  23. channel = client.get_channel(int(channelID))
  24. await channel.send(log_msg)
  25.  
  26.  
  27. @client.event
  28. async def on_ready():
  29. print(client.user.__str__() + " Ready")
  30.  
  31.  
  32. @client.event
  33. async def on_message(msg):
  34. # if msg.author == client.user or msg.author.is_system() or msg.author.bot():
  35. # return
  36. author = msg.author.name
  37.  
  38. try:
  39. messages = users[author] + 1
  40. except:
  41. messages = 1
  42. users.update({author: messages})
  43.  
  44. await log(msg)
  45. await client.process_commands(msg)
  46.  
  47.  
  48. @client.command(name='log_channel')
  49. async def log_channel(ctx, *args):
  50. global channelID
  51.  
  52. if not ctx.channel.name == (command_channel):
  53. await ctx.reply("This command is only avalable in #" + command_channel)
  54. return
  55.  
  56. if not args[0].isdigit():
  57. print("ChannelID " + args[0] + " is invalid")
  58. await ctx.reply(args[0] + " is not a valid channel id")
  59. return
  60.  
  61. channelID = args[0]
  62.  
  63. print("ChannelID " + channelID)
  64.  
  65.  
  66. async def help_message(ctx):
  67. await ctx.reply(f"===HELP===\n" +
  68. " > list <> Returns a list of all users message counts\n" +
  69. " > [username] <> Returns how many messages [username] send\n" +
  70. " > help <> Returns this message")
  71.  
  72.  
  73. async def list_message(ctx):
  74. res = []
  75. for user in users:
  76. res.append(f"{user} {users[user]}\n")
  77. await ctx.reply("===Message Count List===\n" +
  78. "User Messages\n" +
  79. "".join(res) + "\n" +
  80. "'>messages help' for more commands")
  81.  
  82.  
  83. async def user_message_count(ctx, args):
  84. await ctx.reply(f"==={args[0]}'s Message Count===\n" +
  85. f"{args[0]} {users[args[0]]}")
  86.  
  87.  
  88. async def error_message(ctx, args):
  89. await ctx.reply(f"User '{args[0]}' not found or hasn't send any messages yes\n" +
  90. f"Incase you wanted to execute a command use '>messages help' to get a list of all commands since '{args[0]}' isn't a valid command")
  91.  
  92.  
  93. @client.command(name='messages')
  94. async def messages(ctx, *args):
  95. # if not ctx.channel.name == (command_channel):
  96. # await ctx.reply("This command is only avalable in #" + command_channel)
  97. # return
  98.  
  99. if len(args) < 1:
  100. await list_message(ctx)
  101.  
  102. if args[0] in users:
  103. await user_message_count(ctx, args)
  104.  
  105. elif args[0] == "help":
  106. await help_message(ctx)
  107.  
  108. elif args[0] == "list":
  109. await list_message(ctx)
  110.  
  111. else:
  112. await error_message(ctx, args)
  113.  
  114. waiting = True
  115. while waiting:
  116. ct = time.strftime("%d/%m/%Y %H:%M")
  117. wt = "24/05/2022 15:30"
  118. print("\r" + ct + " | " + wt + " | " + str(waiting), end="\r")
  119. if (ct == wt):
  120. waiting = False
  121.  
  122. print("\n")
  123. client.run(token)
  124.  
Advertisement
Add Comment
Please, Sign In to add comment