This repository has been archived by the owner on May 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAttempt 1
92 lines (73 loc) · 3.3 KB
/
Attempt 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
''' Prototype 1 (Date: Oct. 18, 2020)'''
''' Nickolas Rodriguez '''
''' Adam Pena '''
''' Jermeiah Garcia '''
''' Alec Villareal '''
''' Ricky Owkara '''
import discord
from discord.ext import commands
from canvasapi import Canvas
''' DiscordClass contains all of the logic needed to interface with discord '''
class DiscordClass:
#global variable in DiscordClass for Discord bot access
TOKEN = 'insert token'
#global variable in DiscordClass for setting command prefix
client = commands.Bot(command_prefix = '$')
#client event that displays when bot is ready
@client.event
async def on_ready():
print('Bot is ready')
#client event that deletes a specific type of message ($account command inputs)
#@client.event
#async def on_message(message):
# print('Message deleted')
#client command that will take Canvas account information
@client.command(aliasas = ['Log', 'log', 'Acc', 'acc'])
async def account(ctx):
await ctx.send('Saved!')
#client command that will display Canvas account's current courses
@client.command(aliases = ['Co', 'co'])
async def courses(ctx):
response = 'Nothing.'
await ctx.send(f'Here are your courses!\n {(response)}')
#client command that will display Canvas account's current calender events
@client.command(aliasas = ['Cal', 'cal'])
async def calendar(ctx):
response = 'Nothing.'
await ctx.send(f'Here is your calendar!\n {(response)}')
#client command that will display Canvas account's current announcements
@client.command(aliasas = ['Ano', 'ano'])
async def announce(ctx):
response = 'Nothing.'
await ctx.send(f'Here are your announcements!\n {(response)}')
#turns on and runs the discord bot
client.run(TOKEN)
''' CavnasClass contains all the logic needed to interface with Canvas '''
class CanvasClass:
#global variables in CanvasClass for CanvasAPI access
base_url = "https://canvas.instructure.com/api/v1"
access_token = "insert canvas token"
canvas = Canvas(base_url, access_token)
#defined subclass for login in Canvas
def get_account(self, account, use_sis_id=False, **kwargs):
return canvasapi.account.Account
#defined subclass for get_course function in CanvasAPI
def get_course(self, course, use_sis_id=False, **kwargs):
return canvasapi.course.Course
#defined subclass for get_calendar_event function in CavnasAPI
def get_calendar_events(self, **kwargs):
return canvas.calendar_event.CalendarEvent
#defined subclass for get_announcements function in CanvasAPI
def get_announcements(self, **kwargs):
return canvasapi.paginated_list.PaginatedList
''' Creates the bridge for DiscordClass and CanvasClass through simplified logic '''
class Mediator:
#defined subclass for requesting courses
def requestCourses():
return CanvasClass.get_course(self, course, use_sis_id=False, **kwargs)
#defined subclass for requesting calendar events
def requestCalendar():
return CanvasClass.get_calendar_event(self, **kwargs)
#defined subclass for requesting announcements
def requestAnnouce():
return CanvasClass.get_announcements(self, **kwargs)