Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linkedin command #27

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion database.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from pynamodb.models import Model
from pynamodb.attributes import NumberAttribute
from pynamodb.attributes import NumberAttribute, UnicodeAttribute

# condtionally set host meta attribute unless in production.
environment = os.getenv("PYTHON_ENV") or "development"
Expand All @@ -13,8 +13,13 @@ class DiscordUserModel(Model):
class Meta:
table_name = "dynamodb-user"
if environment == "development":
print('using local')
host = "http://localhost:8000"
id = NumberAttribute(hash_key=True)
first_name = UnicodeAttribute(null=True)
last_name = UnicodeAttribute(null=True)
github = UnicodeAttribute(null=True)
linkedin = UnicodeAttribute(null=True)


DiscordUserModel.create_table(read_capacity_units=1, write_capacity_units=1)
77 changes: 77 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from discord.utils import get
import requests
from bs4 import BeautifulSoup
from database import DiscordUserModel

TOKEN = os.environ.get("BOT_TOKEN")

Expand All @@ -23,6 +24,82 @@ async def on_ready():
async def ping(ctx):
await ctx.send('pong')

# Store user's Github username
@client.command(breif="Let us know your Github username so we can connect you with your team!", description="Use '.set_user_github' followed by a ping of the desired discord user and then their Linkedin username all space seperated")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spelling error - breif

async def set_user_github(ctx: commands.Context, discorduser=None, gitusername=None):
if discorduser == None or discorduser[:-1][0] != '<':
return await ctx.send('No user was specified, make sure to ping the desired user after the command')
if gitusername == None:
return await ctx.send('No Github username was specified')
discordid = discorduser.replace("<","").replace("@","").replace("!","").replace(">","")
discordid = int(discordid)
user = None
try:
user = DiscordUserModel.get(discordid)
except DiscordUserModel.DoesNotExist:
user = DiscordUserModel(discordid)

user.github = gitusername
user.save()
await ctx.send(f'Github username saved as https://github.com/{gitusername}')

@client.command(breif="Check which Github username you have stored", description="Use '.get_user_github', then a space, then ping the desird user")
async def get_user_github(ctx: commands.Context, discorduser=None):
if discorduser == None or discorduser[:-1][0] != '<':
return await ctx.send('No user was specified, make sure to ping the desired user after the command')
discordid = discorduser.replace("<","").replace("@","").replace("!","").replace(">","")
discordid = int(discordid)
try:
user = DiscordUserModel.get(discordid)
#user either has or hasnt set value
if user.github:
await ctx.send(f'Github username is saved as https://github.com/{user.github}')
else:
await ctx.send('You have not set this information yet')
except DiscordUserModel.DoesNotExist:
await ctx.send('You have not set any information yet')
return

# Store user's Linkedin username
@client.command(breif="Let us know your Linkedin username", description="Use '.set_user_linkedin' followed by a ping of the desired discord user and then their Linkedin username all space seperated")
async def set_user_linkedin(ctx: commands.Context, discorduser=None, *args):
if discorduser == None or discorduser[:-1][0] != '<':
return await ctx.send('No user was specified. Make sure to ping the desired user after the command')
if len(args) < 1:
return await ctx.send('No Linkedin username was specified')
discordid = discorduser.replace("<","").replace("@","").replace("!","").replace(">","")
discordid = int(discordid)
user = None
try:
user = DiscordUserModel.get(discordid)
except DiscordUserModel.DoesNotExist:
user = DiscordUserModel(discordid)

username = ""
for arg in args:
username = username+" "+arg
username = username[1:]
user.linkedin = username
user.save()
await ctx.send(f'Linkedin username saved as {username}')

@client.command(breif="Check which Linkedin username is associated with a certain user", description="Use '.get_user_linkedin' then a space, then ping the desird user")
async def get_user_linkedin(ctx: commands.Context, discorduser=None):
if discorduser == None or discorduser[:-1][0] != '<':
return await ctx.send('No user was specified. Make sure to ping the desired user after the command')
discordid = discorduser.replace("<","").replace("@","").replace("!","").replace(">","")
discordid = int(discordid)
try:
user = DiscordUserModel.get(discordid)
#user either has or hasnt set value
if user.linkedin:
await ctx.send(f'Linkedin username is saved as {user.linkedin}')
else:
await ctx.send('This user has not set this information yet')
except DiscordUserModel.DoesNotExist:
await ctx.send('This user has not set any information yet')
return

# Stack Overflow searcher
@client.command(brief="Search Stack Overflow", description="Use '.stack' followed by comma separated search terms "
"to search Stack Overflow. (e.g. '.stack python,string,split')")
Expand Down