Commit f1748d19 authored by IS1_4M's avatar IS1_4M
Browse files

Added email tag functionality for UNH Server

parent 7b189ef6
......@@ -89,7 +89,6 @@ class AbstractChannel:# Abstract For club, restricted, and hangout category chan
return self._cli_channel_id
class AbstractChanSuite:
weekdays = ['Monday','Tuesday','Wesnesday','Thursday','Friday','Saturday','Sunday']
'''
Checks to make a channel does not already exist.
'''
......
......@@ -53,7 +53,7 @@ class AdminChannel(AbstractChannel):
async def _init(self):
return await AbstractChannel._init(self, suite=AdminChanSuite)
return await AbstractChannel._init(self, suite=AdminChanSuite) # Add a var channel too and populate it with necessary fields for server functioning.
class AdminChanSuite(AbstractChanSuite):
def get_all_adminchans(guild):
......
......@@ -5,27 +5,25 @@ Created on Sat Sep 5 14:09:29 2020
@author: josep
"""
from handles import User, ECMember, ECStudent, ECFaculty, student_role_name, faculty_role_name, \
general_user_role_names, account_password, bot_token, \
send_account_email, domain_dest, auth_channel,\
MIN_BETWEEN_TASK_EXECUTIONS
import discord
from discord.ext import commands, tasks
import smtplib, ssl
from datetime import datetime, timedelta
from random import random
from asyncio import create_task, sleep, run
from asyncio import sleep
from PublicChannel import PubChanSuite, PublicChan
from ClubChannel import ClubSuite, Club
from restrictedchannel import RestrictChan, RestrictChanSuite
from PublicChannel import PubChanSuite
from ClubChannel import ClubSuite
from restrictedchannel import RestrictChanSuite
from AbstractChannel import AbstractChanSuite
from AdminChannel import AdminChanSuite
from SOCChannel import SOCChannelSuite
from handles import User, ECMember, ECStudent, ECFaculty, Organizer,\
Convener, Admin, SuperAdmin, student_role_name, faculty_role_name, \
general_user_role_names, account_password, bot_token, \
send_account_email, domain_dest, auth_channel,\
MIN_BETWEEN_TASK_EXECUTIONS
from rssfeedtest import get_today_at_earlham
from Response_Handling import handle_response_codes
import json
def get_member_by_discord_name(guild, discord_name):
for member in guild.members:
......@@ -34,7 +32,6 @@ def get_member_by_discord_name(guild, discord_name):
return False
def is_auth(channel, auth_channel_name):
print(channel.name)
return channel.name == auth_channel_name
#for channel in guild.text_channels:
# if channel.name == auth_channel_name:
......@@ -270,7 +267,14 @@ async def on_message(message):
# Always handle remaining response codes at the end.
return await handle_response_codes(message, response)
else:
pass
if message.content.startswith('<@!'):
await ClubSuite.process_at_messages(message)
try:
maybe_auth = is_auth(message.channel, auth_channel)#''' This will break the program later. message.channel can be a DM channel. find a way to make it so that that wont break the channel'''
except:
print('could not find auth channel')
if maybe_auth:
await message.delete(delay=3)
# Check if a message comes in from a CLI channel.
# if in a CLI channel,
# is it an admin channel?
......
......@@ -9,6 +9,7 @@ import discord
from AbstractChannel import AbstractChanSuite, AbstractChannel
from datetime import datetime, timedelta
from handles import MIN_BETWEEN_TASK_EXECUTIONS, PROCESSING_TIME_PADDING
from EmailSuite import EmailSuite
def get_member_by_discord_name(guild, discord_name):
for member in guild.members:
if member.name + "#" + member.discriminator == discord_name:
......@@ -101,7 +102,7 @@ class ClubSuite(AbstractChanSuite):
async def kick_member(club, member, member_role_name=None):
if member_role_name == None:
member_role_name = club.name + ' Member'
member_role_name = club.name + ' ' + Club.member_role_name
await member.remove_roles(ClubSuite.get_role(club, member_role_name))
async def remove_as_convenver(club, member):
......@@ -147,6 +148,8 @@ class ClubSuite(AbstractChanSuite):
async def process_cli_commands(message):
content = message.content.lower()
message_parts = content.split(' ')
message_parts_ = message.content.split(' ')
club = AbstractChanSuite.is_cli(AbstractChanSuite.get_all_chans(message.guild, Club.channel_type), message.channel, Club.convener_role_name)
if not club:
return False # Did not process commands
......@@ -311,9 +314,30 @@ class ClubSuite(AbstractChanSuite):
message.delete()
return 1
return -12
elif content.startswith("!setupemail"): #!setupemail discordname#id:email channel_to_be_active_in
if len(message_parts) != 3:
return -19
if ':' not in message_parts[1]:
return -20
discord_name, dest_email = message_parts_[1].split(':')
# Confirm that the discord user in the server at the moment.
print(discord_name)
user = get_member_by_discord_name(message.guild, discord_name)
if not user:
return -21
# now we know the user is in there. Verify email is valid.
# pass
# and now we know the email is valid. get the specified channel.
chan = AbstractChanSuite.is_text_channel(club, message_parts[-1])
if chan != -15:
pass
else:
return -15
await (await message.channel.send('EMAIL LINK ESTABLISHED IN ' + chan.name + ' . ' + message_parts_[1])).pin()
elif content.startswith('!requestbot'):
return 6#unimplemented. To implement Soon
return False
return 0
async def process_user_commands(message):
# for case sensitive commands.
......@@ -371,10 +395,52 @@ class ClubSuite(AbstractChanSuite):
newClub = Club(message.guild, message.author, clubName)
return await newClub._init()
return False
async def process_user_at_messages(message):
# Verify that we're in a club right now
if not message.content.startswith('<@!'):
return 0
cat = message.channel.category_id
if cat != None:
cat = message.guild.get_channel(cat)
if not cat.name.startswith(Club.channel_type + '-'):
return 0
# And check to see if the mentioned person is linked to an email in the cli.
# Get the linked messages from the cli
cli = ClubSuite.get_cli(cat)
message_parts = message.content.split(' ')
uid = message_parts[0][3:-1]
target_chan = None
discord_user = None
dest_email_addr = None
for pin in await cli.pins():
if pin.content.startswith('EMAIL LINK ESTABLISHED IN '):
pin_parts = pin.content.split(' ')
target_chan = await ClubSuite.get_text_channel(cat, pin_parts[4])
discord_name, dest_email_addr = pin_parts[6].split(':')
discord_user = get_member_by_discord_name(message.guild, discord_name)
# If we mentioned the user in question, email them!
if int(discord_user.id) == int(uid) and message.channel == target_chan:
email, passw = EmailSuite.get_send_email_credentials(message.guild)
await cli.send('Sent email alert to: '+ dest_email_addr + '.', delete_after=3)
EmailSuite.send_email_to_addr(dest_email_addr, email, passw, 'You have been mentioned in ' + message.channel.name + '!', 'Here is the message ' + message.author.name + ' mentioend you in! :\n\t' + discord_name + ' ' + ' '.join(message_parts[1:]))
else:
return 0
async def process_cli_at_messages(message):
return 0
async def process_commands(message):
return await ClubSuite.process_cli_commands(message) or await ClubSuite.process_user_commands(message)
async def process_at_messages(message):
return await ClubSuite.process_cli_at_messages(message) or await ClubSuite.process_user_at_messages(message)
async def process_tasks(clis):
print('processsing tasks')
for cli in clis:
......
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 14 16:04:29 2020
@author: josep
"""
import smtplib, ssl
from handles import send_account_email, account_password
'''
Just a class of email functionalities the bot uses.
'''
class EmailSuite:
def get_send_email_credentials(guild):
# Seperate function right now so that we can change how we get credentials later on
return (send_account_email, account_password)
def send_email_to_addr(to_email, login_email, login_password,
message_subject, message_text, send_by_email=None):
port = 465
context = ssl.create_default_context()
with smtplib.SMTP_SSL("smtp.gmail.com", port, context=context) as server:
server.login(login_email, login_password)
# TODO: Send email here
sender_email = send_by_email if send_by_email else login_email#"@gmail.com"
receiver_email = to_email
message = 'From:'+ sender_email + '\r\nTo: '+receiver_email + """\r\nSubject: """ + message_subject + """\r\n\r\n""" + message_text
server.sendmail(sender_email, receiver_email, message)
server.close()
\ No newline at end of file
......@@ -28,6 +28,10 @@ RESPONSE_CODES = {1: "SUCCEEDED",
-14: "Cant find message in channel error",
-15: "NOT A TEXT CHANNEL IN CATEGORY",
-16: "LIST NOT CLOSED ERROR",
-17: "NOT A WEEKDAY ERROR",
-18: "INVALID TIME FORMAT ERROR",
-19: "EMAILSETUP NEEDS 3 PARTS ERROR",
-21: "USER NOT FOUND ERROR",
-25: "YOU DONT HAVE PERMISSION TO ACCESS",
}
......@@ -58,36 +62,40 @@ async def handle_response_codes(message, code):
elif code == -4:
await message.channel.send("ABSTRACT CHANNEL ALREADY EXISTS: " + message_parts[1], delete_after = 3)
elif code == -5:
await message.channel.send("Sorry... A club by the name " + message_parts[1] + " already exists... Try joining that one? Get help with !help")
await message.channel.send("Sorry... A club by the name " + message_parts[1] + " already exists... Try joining that one? Get help with !help", delete_after = 3)
elif code == -6:
await message.channel.send("Sorry... A RestrictChan by the name " + message_parts[1] + " already exists... Try joining that one? Get help with !help")
await message.channel.send("Sorry... A RestrictChan by the name " + message_parts[1] + " already exists... Try joining that one? Get help with !help", delete_after = 3)
elif code == -7:
await message.channel.send("Sorry... A Public Channel by the name " + message_parts[1] + " already exists... Try joining that one? Get help with !help")
await message.channel.send("Sorry... A Public Channel by the name " + message_parts[1] + " already exists... Try joining that one? Get help with !help", delete_after = 3)
elif code == -9:
await message.channel.send('Aww... ' + '-'.join(message_parts[1:]) + ' hasn\'t set a description yet. Check back later!')
await message.channel.send('Aww... ' + '-'.join(message_parts[1:]) + ' hasn\'t set a description yet. Check back later!', delete_after = 3)
elif code == -10:
await message.channel.send('Sorry... I couldn\'t find a club called ' + '-'.join(message_parts[1:]) + '. Try again and check your spelling?')
await message.channel.send('Sorry... I couldn\'t find a club called ' + '-'.join(message_parts[1:]) + '. Try again and check your spelling?', delete_after = 3)
elif code == -11:
await message.channel.send('Sorry.... I couldn\'t unschedule ' + message.content[len('!unschedule '):] + '. Check your copy-pasting and try again? Copy paste the w-h-o-l-e thing!')
await message.channel.send('Sorry.... I couldn\'t unschedule ' + message.content[len('!unschedule '):] + '. Check your copy-pasting and try again? Copy paste the w-h-o-l-e thing!', delete_after = 3)
elif code == -12:
await message.channel.send('Sorry.... I couldn\'t cancel your meeting... ' + message.content[len('!cancelmeetingtime '):] + '. Check your copy-pasting and try again? Copy paste the w-h-o-l-e thing!')
await message.channel.send('Sorry.... I couldn\'t cancel your meeting... ' + message.content[len('!cancelmeetingtime '):] + '. Check your copy-pasting and try again? Copy paste the w-h-o-l-e thing!', delete_after = 3)
elif code == -13:
await message.channel.send('!removemessage requires 3 things! Here\'s an example: !removemessage MyClubTextChannel text from message i want to remove', delete_after = 10)
elif code == -14:
await message.channel.send("I couldn't find " + ' '.join(message_parts[2:]), 'in' + message_parts[1])
await message.channel.send("I couldn't find " + ' '.join(message_parts[2:]), 'in' + message_parts[1], delete_after = 3)
elif code == -15:
await message.channel.send("Sorry... I couldn't find one of your text channels in your category... Try again?")
await message.channel.send("Sorry... I couldn't find one of your text channels in your category... Try again?", delete_after = 3)
elif code == -16:
await message.channel.send("Hey! Watch your typing! You need a closing bracket ']' if you're going to finish that list correctly!")
await message.channel.send("Hey! Watch your typing! You need a closing bracket ']' if you're going to finish that list correctly!", delete_after = 3)
elif code == -17:
await message.channel.send("Hey!", message_parts[1], "isn't a weekday!")
await message.channel.send("Hey!", message_parts[1], "isn't a weekday!", delete_after = 3)
elif code == -18:
await message.channel.send('Hey! The time part here needs a colon. hr:min in military time. example: 14:02')
await message.channel.send('Hey! The time part here needs a colon. hr:min in military time. example: 14:02', delete_after = 3)
elif code == -19:
await message.channel.send('Hey! !emailsetup takes 2 parameters! as !emailsetup discordname#id:destination_email channel_to_be_active_in !' , delete_after = 3)
elif code == -21:
await message.channel.send("Hey! We couldn't find that user in the discord server at all! Check your spelling and make sure you got their #4numid at the end of their name!", delete_after = 3)
elif code == -25:
await message.channel.send("You don't have permission to execute: " + message_parts[0])
await message.channel.send("You don't have permission to execute: " + message_parts[0], delete_after = 3)
elif type(code) == tuple:
if len(code) == 3 and code[0]==-8:
await message.channel.send('Please no special characters in clubnames (' + code[2] + "). You put: " + code[1])
await message.channel.send('Please no special characters in clubnames (' + code[2] + "). You put: " + code[1], delete_after = 3)
else:
await message.channel.send("You have encountered a mystery error! Reach out to Joseph Islam and he will love to help you get what you're trying to do done. ASAP.")
await message.channel.send("You have encountered a mystery error! Reach out to Joseph Islam and he will love to help you get what you're trying to do done. ASAP.", delete_after = 10)
return 1
\ No newline at end of file
......@@ -209,35 +209,3 @@ class ECFaculty(ECMember):
faculty_role = await guild.create_role(name=faculty_role_name, colour=discord.Colour.teal()) # FIX TO ACTUALLY SUPPORT COLORS LATER
#await faculty_role.set_permissions( blah blah)
await self._member.add_roles(faculty_role)
class Organizer(ECStudent):
def __init__(self):
# Allow access to post in digital advertisement message channel
pass
class Convener(ECStudent):
def __init__(self):
# Give them the ability to kick, ban members from club text, call channels
# Give them club text, call channels.
# Give them ability to post in Digital Advertisement Board.
# Give them channel to issue bot commands for their club:
# Approve members
# Kick, ban, mute, deafen, etc different members.
# Make a new spinoff text channel for their club
# Make a new spinoff voice/video channel for their club
# Delete spinoff channels from their club.
# Request addition of new bots to server for their club.
# Manage new bot locations and permissions.
pass
# Give the member the ECFACULTY role
class Admin(ECMember):
def __init__(self):
# Give them the admin role.
# Give them ability to kick, ban, mute, users across channels.
ECMember.__init__(self)
class SuperAdmin(Admin):
def __init__(self):
# Give ability to close, open new text & voice channels.
Admin.__init__(self)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment