Advertisement
NeonStranger

Untitled

Jul 5th, 2023
1,087
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.49 KB | None | 0 0
  1.  
  2. import json
  3. import discord
  4. import os
  5. from datetime import datetime
  6. import asyncio
  7. from discord.ext import commands
  8. from replit import db
  9.  
  10. messages = joined = 0
  11.  
  12. intents = discord.Intents.default()
  13. intents.members = True
  14. bot = commands.Bot(command_prefix="/", intents=intents)
  15.  
  16. TOKEN = os.environ['TOKEN']
  17.  
  18.  
  19. media_channels = ["media", "bug-reports", "memes"]
  20. WelcomeId = "1006898005426851880"
  21. WelcomeChannel = 0
  22.  
  23. db["servers"] = []
  24.  
  25. #####START
  26. with open("users.json", "ab+") as ab:
  27.     ab.close()
  28.     f = open('users.json','r+')
  29.     f.readline()
  30.     if os.stat("users.json").st_size == 0:
  31.       f.write("{}")
  32.       f.close()
  33.     else:
  34.       pass
  35.  
  36. with open('users.json', 'r') as f:
  37.   users = json.load(f)
  38. #######
  39.  
  40. def update_settings(serverid, newdata):
  41.   db[serverid] = newdata
  42.  
  43. characters_to_remove = "<#>"
  44.  
  45.  
  46.  
  47. async def update_stats():
  48.  
  49.   await bot.wait_until_ready()
  50.   global messages, joined
  51.   while not bot.is_closed():
  52.       try:
  53.         now = datetime.now()
  54.         dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
  55.         with open("stats.txt", "a") as f:
  56.           f.write(f"Time: {dt_string}, Messages: {messages}, Members Joined: {joined}\n")
  57.          
  58.         messages = 0
  59.         joined = 0
  60.  
  61.         await(asyncio.sleep(7200))    
  62.        
  63.       except Exception as e:
  64.         print(e)
  65.         await(asyncio.sleep(7200))      
  66.  
  67. @bot.event
  68. async def on_guild_join(guild):
  69.   print(guild)
  70.  
  71.  
  72. @bot.command()
  73. async def clear(ctx, info):
  74.   async for message in ctx.channel.history(limit=int(info)):
  75.     await message.delete()
  76.  
  77. @bot.command()
  78. async def embed(ctx):
  79.   async for message in ctx.channel.history(limit=1):
  80.     await message.delete()
  81.     embedVar = discord.Embed(title= "Server Rules", description= "**INAPPROPRIATE CONVERSATION**\n\n- Sex\n- Drugs/Alcohol\n   \t \ Medical or educational discussion about drugs are allowed\n   \t \ Promotion of drug use or distribution of drugs is not allowed.\n- Swearing is permitted if not used excessively or in a derogatory way.\n    \t \ Words or phrases deemed too inappropriate will still be moderated\n- Controversial or sensitive topics (religion, political, etc)\n- Racism, sexism, transphobia, homophobia, harassment\n- Discussing any moderation actions. Please submit a ticket to discuss further.\n- Discussions of exploiting\n   \t \ This applies to how to make an exploit, and how to use\n\n**PROVOKING, TARGETING, HARASSMENT**\n\n- Bullying: negatively targeting the user in direct messages, constantly pinging them with negative remarks, etc\n- Racism, sexism, trans-phobia, homophobia, harassment or threatening another user\n   \t \ Provoking phobias with intent to upset or bother another user, if asked to not post something such as an image of a spider please respect their request.\n- Provoking, baiting, stimulating intense situations, or deliberately making users respond in a hostile manner is not tolerated. (including, but not limited to, arguing, exploiting rules and loopholes, and intentionally inciting moderators to take action.\n- Encouraging suicide\n\n**PLEASE NOTE:** Giving criticism is not considered any of these. However, if you're strictly targeting someone and continuously saying their work is bad without any suggested improvements is considered harassment.**", color= 0xE17B24)
  82.     await ctx.channel.send(embed=embedVar)
  83.    
  84. default_roles = ["1006898005426851880"]
  85.  
  86. @bot.command()
  87. @commands.is_owner()
  88. async def reload(ctx, extension):
  89.     bot.reload_extension(f"cogs.{extension}")
  90.     embed = discord.Embed(title='Reload', description=f'{extension} successfully reloaded', color=0xff00c8)
  91.     await ctx.send(embed=embed)
  92.  
  93. @bot.command()
  94. async def setwelcomechannel(ctx, a):
  95.   att = ""
  96.   for character in characters_to_remove:
  97.     a = a.replace(character, "")
  98.     att = a
  99.   print(att)
  100.   for channel in ctx.guild.channels:
  101.     print(str(channel.id) + " " + channel.name)
  102.     if att == str(channel.id):
  103.         global WelcomeId
  104.         WelcomeId = channel.id
  105.         await ctx.channel.send("Set welcome channel to " + channel.mention + "!")
  106.         return
  107.   await ctx.channel.send("That's not a valid channel!")
  108.  
  109. @bot.event
  110. async def on_member_join(member):
  111.   ##level stuff
  112.  
  113.   ##
  114.   global joined
  115.   joined += 1
  116.   now = datetime.now()
  117.   WelcomeChannel = bot.get_channel(WelcomeId)
  118.   dt_string = now.strftime("%H:%M:%S")
  119.   div1 = discord.utils.get(member.guild.roles, id=1006898005426851880)
  120.   div2 = discord.utils.get(member.guild.roles, id=1006897042896978000)
  121.   div3 = discord.utils.get(member.guild.roles, id=1006897978994331760)
  122.   div4 = discord.utils.get(member.guild.roles, id=1006895890843304037)
  123.   member_role = discord.utils.get(member.guild.roles, id=1007683496464093194)
  124.   await member.add_roles(div1)
  125.   await member.add_roles(div2)
  126.   await member.add_roles(div3)
  127.   await member.add_roles(div4)
  128.   await member.add_roles(member_role)
  129.   with open("members.txt", "a") as f:
  130.     f.write(f"[{dt_string}]: {member.name} has just joined!\n")
  131.   await WelcomeChannel.send("Welcome " + member.mention + "!")
  132.  
  133.  
  134. @bot.event
  135. async def on_message(message):
  136.   ## Process Commands
  137.   if not message.author == bot.user:
  138.     with open('users.json', 'r') as f:
  139.         users = json.load(f)
  140.     await add_experience(users, message.author)
  141.     await level_up(users, message.author, message)
  142.     with open('users.json', 'w') as f:
  143.         json.dump(users, f)
  144.         await bot.process_commands(message)
  145.     await bot.process_commands(message)
  146.     Channel = message.channel
  147.     print("")
  148.     ##Level
  149.  
  150.     ##
  151.     now = datetime.now()
  152.     dt_string = now.strftime("%H:%M:%S")
  153.     with open("message_logs/all.txt", "a") as f:
  154.       f.write(f"[{dt_string}]: {message.author.name} - {message.content}\n")
  155.   ## Add to Stats
  156.     global messages
  157.     messages += 1
  158.   ## Media Filter
  159.     if message.attachments:
  160.       if not Channel in media_channels:
  161.          await message.delete()
  162.   ##
  163.  
  164.  
  165.  
  166. ##Levels
  167. async def add_experience(users, user):
  168.   if not f'{user.id}' in users:
  169.     users[f'{user.id}'] = {}
  170.     users[f'{user.id}']['experience'] = 0
  171.     users[f'{user.id}']['level'] = 0
  172.   users[f'{user.id}']['experience'] += 6
  173.   print(f"{users[f'{user.id}']['level']}")
  174.  
  175. async def level_up(users, user, message):
  176.   experience = users[f'{user.id}']["experience"]
  177.   lvl_start = users[f'{user.id}']["level"]
  178.   lvl_end = int(experience ** (1 / 4))
  179.   if lvl_start < lvl_end:
  180.     await message.channel.send(f':tada: {user.mention} has reached level {lvl_end}. Congrats! :tada:')
  181.     users[f'{user.id}']["level"] = lvl_end
  182.  
  183. @bot.command()
  184. async def rank(ctx, member: discord.Member = None):
  185.   if member == None:
  186.       userlvl = users[f'{ctx.author.id}']['level']
  187.       #await ctx.send(f'{ctx.author.mention} You are at level {userlvl}!')
  188.       exp = users[f'{ctx.author.id}']["experience"]
  189.       embed1 = discord.Embed(title = 'Level {}'.format(userlvl), description = f"{exp} XP " ,color = discord.Color.green())
  190.       embed1.set_author(name = ctx.author, icon_url = ctx.author.avatar_url)
  191.       await ctx.send(embed = embed1)
  192.   else:
  193.       userlvl2 = users[f'{member.id}']['level']
  194.       #await ctx.send(f'{member.mention} is at level {userlvl2}!')
  195.       exp = users[f'{member.id}']["experience"]
  196.       embed2 = discord.Embed(title = 'Level {}'.format(userlvl2), description = f"{exp} XP " ,color = discord.Color.green())
  197.       embed2.set_author(name = member, icon_url = member.avatar_url)
  198.       await ctx.send(embed = embed2)
  199.  
  200. #############
  201.  
  202. bot.loop.create_task(update_stats())
  203. bot.run(TOKEN)
  204.  
  205.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement