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 6
101 lines (91 loc) · 5.08 KB
/
Attempt 6
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
93
94
95
96
97
98
99
100
101
import Discord
from discord.ext import commands
from canvasapi import Canvas
TOKEN = 'insert discord bot token'
client = commands.Bot(command_prefix = '$')
base_url = "empty"
access_token = "empty"
class CanvasBot:
@client.event
async def on_ready():
print('Bot is ready')
'''Info command that shows all of the current commands for the current version of the code'''
@client.command(aliases = ['i', 'I'])
async def info(ctx):
message = ("__**Welcome to Canvas Bot.**__"
+ "\n *Courses command*"
+ "\n Type **$courses**, **$c** or **$C** to display all of your currently enrolled."
+ "\n *Event command*"
+ "\n Type **$events**, **$e** or **$E** to display all of your current events."
+ "\n *Announcment command*"
+ "\n Type **$announcements**, **$a** or **$A** to display all of your current announcements for a specific course."
+ "\n Type **$setup**, **$s** or **$S** to setup your credentials for the Canvas Bot!")
await ctx.author.send(message)
'''Course command that shows all of the current courses for a specific user'''
@client.command(aliases = ['c', 'C'])
async def courses(ctx):
global base_url
global access_token
if (base_url == "empty" or access_token == "empty"):
await ctx.channel.send("**Invalid command!** \nPlease insert proper credentials through the **$setup** command. \nCheck **$info** for help.")
else:
canvas = Canvas(base_url,access_token)
list = canvas.get_courses()
for courses in list:
await ctx.channel.send(f'*Name:* **{courses.name}** \n *Course ID:* {courses.id} \n*Course Code:* _{courses.course_code}_')
await ctx.channel.send('__**Here are your current courses!**__'
+ "```\nOutputs include the course's: "
+ '\nName: [course name] \nCourse ID: [id] \nCourse Code: [code]```')
'''Event command that shows all of the current events for a specific user'''
@client.command(aliases = ['e', 'E'])
async def events(ctx):
global base_url
global access_token
if (base_url == "empty" or access_token == "empty"):
await ctx.channel.send("**Invalid command!** \nPlease insert proper credentials through the **$setup** command. \nCheck **$info** for help.")
else:
canvas = Canvas(base_url, access_token)
list = canvas.get_calendar_events(all_events = "true")
for event in list:
await ctx.channel.send(f'*Title:* **{event.title}** \n *Start:* {event.start_at} \n *End:* {event.end_at} \n *Description:* {event.description}')
await ctx.channel.send('__**Here are all of your events!**__'
+ "```\nOutputs include the event's: "
+ '\nTitle: [title] \nStart: [start date] \nEnd: [end date] \nDescription: [description]```')
'''Announcement command that shows all of the current announcements for a specific class'''
@client.command(aliases = ['a', 'A'])
async def announcements(ctx):
global base_url
global access_token
if (base_url == "empty" or access_token == "empty"):
await ctx.channel.send("**Invalid command!** \nPlease insert proper credentials through the **$setup** command. \nCheck **$info** for help.")
else:
canvas = Canvas(base_url, access_token)
list = canvas.get_announcements(context_codes = "course_2421114")
for announce in list:
await ctx.channel.send(f'*Title:* **{announce.title}** \n *Message:* {announce.message} \n *Posted:* {announce.posted_at}')
await ctx.channel.send('__**Here are your current announcements!**__'
+ "```\nOutputs include the announcement's: "
+ '\nTitle: [title] \nMessage: [message] \nPosted: [posted date]```')
@client.command()
async def files(ctx):
global base_url
global access_token
if (base_url == "empty" or access_token == "empty"):
await ctx.channel.send("**Invalid command!** \nPlease insert proper credentials through the **$setup** command. \nCheck **$info** for help.")
else:
canvas = Canvas(base_url, access_token)
list = canvas.get_file()
for files in list:
await ctx.channel.send(f'{files.display_name}')
await ctx.channel.send('__**Here are your current files!**__'
+ "```\nOutputs include the announcement's: "
+ '\nTitle: [title] \nMessage: [message] \nPosted: [posted date]```')
class CanvasBot_Setup():
@client.command(aliases = ['s', 'S'])
async def setup(ctx, base, access):
global base_url
global access_token
base_url = base
access_token = access
await ctx.author.send(f'Here are your inputs: \nBase_url: {base_url} \nAccess_token: {access_token}')
client.run(TOKEN)