Advertisement
Jarquafelmu

mycog

Sep 5th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.02 KB | None | 0 0
  1. import discord
  2. from redbot.core import commands
  3. from redbot.core.i18n import Translator, cog_i18n
  4. from redbot.core.utils.menus import menu, DEFAULT_CONTROLS
  5. from redbot.core.utils.chat_formatting import escape, italics, pagify
  6.  
  7.  
  8.  
  9. class Csswelcome:
  10.   """My custom cog"""
  11.  
  12.   def __init__(self, bot):
  13.     self.bot = bot
  14.  
  15.   # callable functions
  16.   async def welcome(self, channel = None, member = None):
  17.     """
  18.    Helper function to handle the welcoming of a user
  19.    """
  20.  
  21.     # We don't want to do anything if we don't have a channel or a member
  22.     if channel is None or member is None:
  23.       return
  24.  
  25.     channel_serverGuidelines_id = 482361843588005940
  26.     channel_roles_id = 482361038478508034
  27.  
  28.     await channel.send(f"Welcome {member.mention}! Please take a moment to go over the <#{channel_serverGuidelines_id}> and let us know in <#{channel_roles_id}> which classes you are in.")
  29.  
  30.   async def pastGreet(self, ctx = None):
  31.     """
  32.    Greets members that joined the server while the bot was unavailable
  33.    """
  34.  
  35.     channel_newMembers_id = 484378858968055814
  36.     channel_newMembers = self.bot.get_channel(channel_newMembers_id)
  37.  
  38.     recentlyJoinedMembers = []
  39.     messageLimit = 50
  40.  
  41.     # scan through the `messageLimit` most recent messages, add any new member announcment to the list of
  42.     # `recentlyJoinedMembers` exit as soon as there is message from the bot found
  43.     async for message in channel_newMembers.history(limit=messageLimit):
  44.       if not message.author.bot:
  45.         recentlyJoinedMembers.append(message)
  46.       else:
  47.         break
  48.  
  49.     if len(recentlyJoinedMembers) is 0:
  50.       self.log.send("No new members found since I was last online.")
  51.  
  52.     for member in recentlyJoinedMembers:
  53.       await self.welcome(channel_newMembers, member.author)
  54.  
  55.  
  56.   # user commands
  57.   @commands.command(name="greet", aliases=['hi'])
  58.   async def greet(self, ctx, user: discord.Member = None):
  59.     """
  60.    Welcomes a user to the server
  61.    """
  62.     chlServerGuidelines = "<#482361843588005940>"
  63.     chlRoles = "<#482361038478508034>"
  64.  
  65.     if user is None:
  66.       user = ctx.author
  67.    
  68.     await self.welcome(ctx, user)
  69.  
  70.   @commands.command()
  71.   async def roles(self, ctx, user: discord.Member = None):
  72.     """
  73.      Shows the roles the user has
  74.  
  75.      Defaults to author
  76.    """
  77.  
  78.     if user == None:
  79.       user = ctx.author
  80.  
  81.     roles = user.roles
  82.  
  83.     roleStr = ""
  84.     for role in roles:
  85.       if role.name != "@everyone":
  86.         roleStr += '\n' + role.name
  87.  
  88.     await ctx.send(f"User: **{user.display_name}** has the following roles: \n{roleStr}")
  89.  
  90.  
  91.   #custom events
  92.   async def is_loaded(self):
  93.     """
  94.      Announces that the bot is loaded
  95.    """
  96.  
  97.     channel_logging_id = 485218362272645120
  98.     channel_logging = self.bot.get_channel(channel_logging_id)
  99.  
  100.     await channel_logging.send(f"Bot is loaded and ready.")
  101.     await self.pastGreet()
  102.  
  103.   #event triggers
  104.   async def on_member_join(self, member):
  105.     """
  106.    Welcome's a new user to the server
  107.    """
  108.     chlServerGuidelines = "<#482361843588005940>"
  109.     chlRoles = "<#482361038478508034>"
  110.     channel = self.bot.get_channel(484378858968055814)
  111.  
  112.     await channel.send(f"Welcome {member.mention}! Please take a moment to go over the {chlServerGuidelines} and let us know in {chlRoles} which classes you are in.")
  113.  
  114.   async def on_message(self, message):
  115.     """
  116.      Gets and parses a user message for what classes they are in
  117.    """
  118.  
  119.     #channel ids
  120.     channel_roles_id = 482361038478508034
  121.  
  122.     if message.author.bot or not message.channel.id == channel_roles_id:
  123.       return
  124.  
  125.     channel_logging_id = 485218362272645120
  126.     channel_logging = self.bot.get_channel(channel_logging_id)
  127.  
  128.     await channel_logging.send(f"**{message.author.display_name}** (#{message.channel}) said: *\"{message.content}\"*")
  129.  
  130.  
  131.     #create channel
  132.     #guild.create_category_channel, I thinlk?
  133.  
  134.   #@commands.command()
  135.   #async def multi(self, ctx, *, args):
  136.   # argslist = args.split()
  137.   # await ctx.send("-".join(argslist))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement