From 2d1ba13cd571b85c9ec9f29a44e6104100ddda14 Mon Sep 17 00:00:00 2001 From: Nickolas Rodriguez <52770090+Nick-prog@users.noreply.github.com> Date: Mon, 16 Nov 2020 16:37:26 -0600 Subject: [PATCH 1/2] Decoupling Started the process of decoupling the code, but need to figure out how to make it run. Current issue: Canvas Class and its subclasses/functions can't interact with Discord Class and its subclass/functions. --- Attempt4Version1 | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 Attempt4Version1 diff --git a/Attempt4Version1 b/Attempt4Version1 new file mode 100644 index 0000000..a7a1db3 --- /dev/null +++ b/Attempt4Version1 @@ -0,0 +1,82 @@ +import Discord +from discord.ext import commands +from canvasapi import Canvas + +class DiscordClass(): + TOKEN = 'NzYyNDEzMjc1OTEyNjAxNjUx.X3oysQ.9GG7OHxOvM3xYCWb5EeA7OiWMuw' + client = commands.Bot(command_prefix = '$') + + @client.event + async def on_ready(): + print('Bot is ready') + + @client.command() + async def test(ctx): + base_url1 = 'https://canvas.instructure.com/' #URL for website + access_token1 = '7~7d5FoNdWiZFO6UkTxuPONLRxxQ9sXAybjiog8vNpwE0RA3D75VYcAeDkzKSMfNjR' #Access token registered to the user's acccount + canvas = Canvas(base_url1, access_token1) #Initializes the Canvas object + print(canvas) #Simple print statement to show completion + + ''' Uses a course id in the get_course function to find the user's id ''' + course_id = 2421114 #Course id the user currently is in + course = canvas.get_course(course_id) #Uses the get_course function to pass course id + user = course.get_users(search_term = 'Nickolas Rodriguez') #Searches the course for a user with the given name + user_id = user[0] #Accesses the first entry of the paginated list retrieved + print(user_id) #Prints results in command console + + ''' Uses user id recieved to test if the get_user function works ''' + user1 = course.get_user(id_type = id, user = user_id) #Uses get_user function to pass user id + print(user1) #Prints results in command console + + ''' Uses get_courses function to display all of the courses the user is in ''' + course1 = canvas.get_courses() #Uses get_courses function to find out all user registered courses + print(course1) #Prints result without properly accessing the paginated list + print(course1[0]) #Prints result of the first entry in the paginated list retrieved + print(course1[1]) #Prints result of the second entry in the panginated list retrieved + + class Discord_Setup(): + @client.command + async def setup(ctx): + arg1 = 'https://canvas.instructure.com/' + arg2 = '7~7d5FoNdWiZFO6UkTxuPONLRxxQ9sXAybjiog8vNpwE0RA3D75VYcAeDkzKSMfNjR' + await ctx.send("Base URL = " + arg1 + ", Access Token = " + arg2) + + class Discord_User(): + @client.command() + async def user(ctx): + discord = CanvasClass() + result = discord.user + arg = '28468322' + result(arg) + await ctx.send("User information: " + result) + + class Discord_Courses(): + @client.command() + async def courses(ctx): + discord = CanvasClass.Canvas_Courses() + result = discord.course + await ctx.send("Courses: " + result) + + + client.run(TOKEN) + +class CanvasClass(DiscordClass): + + class Canvas_Setup(): + def setup(): + discord = DiscordClass() + base_url = discord.setup(arg1) + access_url = discord.setup(arg2) + canvas = Canvas(base_url, access_token) + + + class Canvas_User(): + def user(self,**kwargs): + user_return = canvas.get_user(**kwargs) + return(user_return[0]) + + class Canvas_Courses(): + def course(): + course_return = canvas.get_course() + return(course_return[0]) + From 49f064d17ed4aff070a519d0723615072b2f410b Mon Sep 17 00:00:00 2001 From: Nickolas Rodriguez <52770090+Nick-prog@users.noreply.github.com> Date: Mon, 16 Nov 2020 16:38:41 -0600 Subject: [PATCH 2/2] Update Attempt4Version1 --- Attempt4Version1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Attempt4Version1 b/Attempt4Version1 index a7a1db3..b9b2855 100644 --- a/Attempt4Version1 +++ b/Attempt4Version1 @@ -3,7 +3,7 @@ from discord.ext import commands from canvasapi import Canvas class DiscordClass(): - TOKEN = 'NzYyNDEzMjc1OTEyNjAxNjUx.X3oysQ.9GG7OHxOvM3xYCWb5EeA7OiWMuw' + TOKEN = 'enter token' client = commands.Bot(command_prefix = '$') @client.event