Skip to content

Commit 3e2cc81

Browse files
committed
/instructor_disconnect
1 parent e1543dd commit 3e2cc81

File tree

6 files changed

+151
-5
lines changed

6 files changed

+151
-5
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## /instructor_disconnect
2+
3+
- :heavy_check_mark: Can be used in every channel.
4+
- :heavy_check_mark: Reply with an ephemeral message - is only visible to the user of the interaction.
5+
- :heavy_check_mark: Needs argument: user to disconnect from voice chat.
6+
- :heavy_check_mark: Admin and faculty can disconnect anyone from any voice chat.
7+
- :heavy_check_mark: Instructor can disconnect a user from course voice chat only if they are instructor in that specific course.
8+
- :x: All members can use this command.
9+
- :x: Can give the intructor role to a member who is not on the course.

documentation/usermanual-admin.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ Command | Explanation | Arguments
134134
[/unhide_course](./commands/faculty/unhide_course.md) | Make given course public, e.g., /unhide_course weba. | :heavy_check_mark:
135135
[/unlock_chat](./commands/faculty/unlock_chat.md) | Unlock the chat of a given course | :heavy_check_mark:
136136

137+
#### Instructor specific commands ####
138+
139+
Command | Explanation | Arguments
140+
--------|-------------|----------:
141+
[/instructor_disconnect](./commands/instructor/instructor_disconnect.md) | Disconnect another user from a voice chat, e.g., /instructor_disconnect @user1. | :heavy_check_mark:
142+
137143
#### General commands ####
138144

139145
Command | Explanation | Arguments

documentation/usermanual-faculty.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ To be able to use all the faculty commands, you need to authenticate yourself. U
3838

3939
You can create new course with command `/create_course`. Give the command and after that give the _course code_, course´s _full name_ and course´s _nickname_. Nickname is optional and if not given then the coursecode will be also course´s nickname. **Note** that nickname is the value that is used as course´s name that users see on the Discord´s left column. So, we prefer that you give your course a short nickname because it is more readable on Discord for the users. **Note** also that nickname is a unique value.
4040

41-
#### Multilingual course name
42-
43-
If your course has multilingual course name, enter all the information in the _full name_ field.
44-
4541
#### Open university course
4642

4743
If your course is an open university course, use the abbreviation **MOOC** in the _full name_ field next to your course name.
@@ -130,6 +126,10 @@ Users with faculty rights can hide a text channel from regular users inside a co
130126

131127
To reveal the channel to regular users, write the command `/unhide_channel` on that channel. Note that the command also enables the bridge on that channel.
132128

129+
### Disconnecting users from voice chat
130+
131+
You can disconnect another user from any voice chat with the command `/instructor_disconnect`. Simply type `/instructor_disconnect @user1` in any chat.
132+
133133
#### Faculty specific commands ####
134134

135135
Command | Explanation | Arguments
@@ -138,7 +138,7 @@ Command | Explanation | Arguments
138138
[/create_channel](./commands/faculty/create_channel.md) | Create new text channel inside a course, e.g., /create_channel feedback. | :heavy_check_mark:
139139
[/create_course](./commands/faculty/create_course.md) | Create a new course | :heavy_check_mark:
140140
[/create_poll](./commands/faculty/create_poll.md) | Create a new poll | :heavy_check_mark:
141-
[/delete_bridge](./commands/faculty/delete_bridge.md) | Delete the bridge from specified Course, e.g., /delete_bridge ohpe | :heavy_check_mark:
141+
[/delete_bridge](./commands/faculty/delete_bridge.md) | Delete the bridge from specified course, e.g., /delete_bridge ohpe | :heavy_check_mark:
142142
[/delete_channel](./commands/faculty/delete_channel.md) | Remove given text channel inside a course, e.g., /delete_channel feedback. | :heavy_check_mark:
143143
[/disable_bridge](./commands/faculty/disable_bridge.md) | Disable the bridge between Telegram and the (non-default) course channel it is used in. | :x:
144144
[/edit_course](./commands/faculty/edit_course.md) | Edit course information, options; coursecode, full name, nickname | :heavy_check_mark:
@@ -154,6 +154,12 @@ Command | Explanation | Arguments
154154
[/unhide_course](./commands/faculty/unhide_course.md) | Make given course public, e.g., /unhide_course weba. | :heavy_check_mark:
155155
[/unlock_chat](./commands/faculty/unlock_chat.md) | Unlock the chat of a given course | :heavy_check_mark:
156156

157+
#### Instructor specific commands ####
158+
159+
Command | Explanation | Arguments
160+
--------|-------------|----------:
161+
[/instructor_disconnect](./commands/instructor/instructor_disconnect.md) | Disconnect another user from a voice chat, e.g., /instructor_disconnect @user1. | :heavy_check_mark:
162+
157163
#### General commands ####
158164

159165
Command | Explanation | Arguments
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# User manual for instructors
2+
3+
### About Discord
4+
5+
To learn more about Discord in general, head over to their [official website](https://discord.com/). You can also check the [Beginner's Guide to Discord](https://support.discord.com/hc/en-us/articles/360045138571-Beginner-s-Guide-to-Discord#h_d33e3809-909b-4720-899d-db26c17bafa9).
6+
7+
The Department of Computer Science has a Discord server for course support. The server contains categories for courses where students can ask for help and offer peer support for other students. The server also has a bot that can help you with several things, including creating course categories, adding instructors for a course, editing course visibility, and more.
8+
9+
We recommend that you use the Discord application (desktop app or mobile app). If you can't or don't want to download the application, you can use a browser-based version of Discord instead.
10+
11+
### Create your Discord account
12+
13+
Create yourself a Discord account. You can do this on [Discord Website](https://discord.com/). If you already have the account, you can login [here](https://discord.com/login).
14+
15+
If you’re on a desktop or mobile device, you can directly open the Discord app on your device (You can learn more information on downloading the app [here](https://support.discord.com/hc/en-us/articles/360033931551)).
16+
17+
Once you’re at the login page, type in either _your email address_ or _phone number_ that has been officially verified to your Discord account.
18+
19+
Note: You will need to verify your phone number to your Discord account before using phone number login! [Click here](https://support.discord.com/hc/en-us/articles/360033931551) to learn how to verify your phone number to your Discord account.
20+
21+
### Joining to the Discord
22+
23+
You can join to the Helsinki University Discord server in two different ways. Join directly to the server using this [link]( https://study.cs.helsinki.fi/discord). Join directly using the course´s own link (MOOC, Moodle, etc.).
24+
25+
![commands](./images/courselink.png)
26+
27+
### How to use the bot
28+
29+
The Discord server has a bot that can help you with many things. Interaction with bot is achieved with Discord's slash commands.
30+
31+
Commands can be used by typing `/<command_name>` into the message area at the bottom of the application. You can see all the available commands as a list that opens after typing `/`. **Note that you have to manually type the commands; the bot rarely understands copy-pasted commands!**
32+
33+
### Disconnecting users from course voice chat
34+
35+
You can disconnect another user from course voice chat with the command `/instructor_disconnect`. Note that you can disconnect a user only if you are an instructor on that course. E.g. if you are a course instructor in tito, `@user1` is currently in `tito_voice`, and `@user2` is in `wepa_voice`, you can disconnect `@user1` by typing `/instructor_disconnect @user1` in any chat, whereas using `/instructor_disconnect @user2` will do nothing as you are not an instructor in wepa.
36+
37+
#### Instructor specific commands ####
38+
39+
Command | Explanation | Arguments
40+
--------|-------------|----------:
41+
[/instructor_disconnect](./commands/instructor/instructor_disconnect.md) | Disconnect another user from a voice chat, e.g., /instructor_disconnect @user1. Only works for persons in voice chat of a course you are instructor in. | :heavy_check_mark:
42+
43+
### General commands
44+
45+
Command | Explanation | Arguments
46+
--------|-------------|----------:
47+
[/auth](./commands/general/auth.md) | For faculty members with student role to acquire the faculty role. | :x:
48+
[/courses](./commands/general/courses.md) | Get public course information | :x:
49+
[/help](./commands/general/help.md) | Get help how to use slash commands. | :o:
50+
[/instructors](./commands/general/instructors.md) | Get course intructors information. | :x:
51+
[/join](./commands/general/join.md) | Joins you into the course given, e.g., /join ohpe. | :heavy_check_mark:
52+
[/leave](./commands/general/leave.md) | Remove you from the course given, e.g., /leave ohpe. | :heavy_check_mark:
53+
[/workshops](./commands/general/workshops.md) | Get workshop info for the course. | :x:
54+
55+
### Material
56+
57+
[Source code for the Bot](https://github.com/Ohtuproju2021syksy/Discord-Bot-better)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
const { SlashCommandBuilder } = require("@discordjs/builders");
2+
const { getChannelByDiscordId } = require("../../../db/services/channelService");
3+
const { findUserByDiscordId } = require("../../../db/services/userService");
4+
const { sendEphemeral, editEphemeral, editErrorEphemeral } = require("../../services/message");
5+
const { confirmChoice } = require("../../services/confirm");
6+
const { findCourseMember } = require("../../../db/services/courseMemberService");
7+
const { getUserWithUserId } = require("../../services/service");
8+
9+
const execute = async (interaction, client, models) => {
10+
await sendEphemeral(interaction, "Disconnecting user from voice channel...");
11+
12+
const channelModel = models.Channel;
13+
const courseMemberModel = models.CourseMember;
14+
15+
const parameter = interaction.options.getString("user");
16+
if (!parameter.match(/(?<=<@!).*?(?=>)/)) {
17+
return await editErrorEphemeral(interaction, "Invalid parameters.");
18+
}
19+
const userToDisconnectID = parameter.match(/(?<=<@!).*?(?=>)/)[0];
20+
const commandUser = await findUserByDiscordId(interaction.member.user.id, models.User);
21+
const userToDc = await getUserWithUserId(client.guild, userToDisconnectID);
22+
const userToDcVoiceChannel = await getChannelByDiscordId(userToDc.voice.channelId, channelModel);
23+
console.log(userToDcVoiceChannel);
24+
25+
26+
// inside a course voice channel
27+
if (userToDcVoiceChannel?.courseId) {
28+
const commandUserCourseMember = await findCourseMember(commandUser.id, userToDcVoiceChannel.courseId, courseMemberModel);
29+
console.log(commandUserCourseMember);
30+
if (!commandUser.admin && !commandUser.faculty && !commandUserCourseMember.instructor) {
31+
return await editErrorEphemeral(interaction, "You don't have the permissions to do that.");
32+
}
33+
const confirm = await confirmChoice(interaction, `Confirm command: Disconnect user ${parameter} from voice channel`);
34+
35+
if (!confirm) {
36+
return await editEphemeral(interaction, "Command declined");
37+
}
38+
userToDc.voice.setChannel(null);
39+
return await editEphemeral(interaction, `Disconnected user ${parameter} from voice channel`);
40+
}
41+
42+
// inside a non-course voice channel
43+
if (!commandUser.admin && !commandUser.faculty) {
44+
return await editErrorEphemeral(interaction, "You don't have the permissions to do that.");
45+
}
46+
const confirm = await confirmChoice(interaction, `Confirm command: Disconnect user ${parameter} from voice channel`);
47+
48+
if (!confirm) {
49+
return await editEphemeral(interaction, "Command declined");
50+
}
51+
userToDc.voice.disconnect();
52+
await editEphemeral(interaction, `Disconnected user ${parameter} from voice channel`);
53+
};
54+
55+
module.exports = {
56+
data: new SlashCommandBuilder()
57+
.setName("instructor_disconnect")
58+
.setDescription("Disconnect user from voice channel.")
59+
.setDefaultPermission(true)
60+
.addStringOption(option =>
61+
option.setName("user")
62+
.setDescription("User to disconnect.")
63+
.setRequired(true)),
64+
execute,
65+
usage: "/instructor_disconnect",
66+
description: "Disconnect user from voice channel.*",
67+
};

src/discordBot/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const intents = [
1111
Intents.FLAGS.GUILD_INVITES,
1212
Intents.FLAGS.GUILD_MESSAGES,
1313
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
14+
Intents.FLAGS.GUILD_VOICE_STATES,
1415
];
1516
const client = new Client({ intents: intents });
1617

0 commit comments

Comments
 (0)