-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathForChannels.cs
More file actions
112 lines (99 loc) · 3.91 KB
/
Copy pathForChannels.cs
File metadata and controls
112 lines (99 loc) · 3.91 KB
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
102
103
104
105
106
107
108
109
110
111
112
using Discord.Rest;
using Discord.WebSocket;
using Discord;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LVCMod
{
partial class Bot
{
/// <summary>
/// Create a voice channel
/// </summary>
/// <param name="channelName">Channel Name</param>
/// <param name="canTalk">Everyone can talk in the voice chat</param>
/// <returns>RestVoiceChannel</returns>
public async Task<RestVoiceChannel> CreateVoiceChannel(string channelName, bool canTalk = true)
{
RestVoiceChannel newChannel = await Guild.CreateVoiceChannelAsync(
channelName,
c =>
{
c.CategoryId = GetCategoryByName(Mod.Config.Bot.VoiceChatsCategoryName).Id;
if (canTalk)
return;
c.PermissionOverwrites = new Optional<IEnumerable<Overwrite>>(
new List<Overwrite>()
{
new Overwrite(
Guild.EveryoneRole.Id,
PermissionTarget.Role,
new OverwritePermissions(
speak: PermValue.Deny,
sendMessages: PermValue.Deny,
useExternalSounds: PermValue.Deny
)
)
}
);
}
);
return newChannel;
}
/// <summary>
/// Create the Main Category for the bot voice channels
/// </summary>
/// <returns>RestCategoryChannel</returns>
public async Task<RestCategoryChannel> CreateVoiceChatsCategory()
{
RestCategoryChannel newCategory = await Guild.CreateCategoryChannelAsync(Mod.Config.Bot.VoiceChatsCategoryName);
return newCategory;
}
/// <summary>
/// Delete a voice channel if the condition is true or null
/// </summary>
/// <param name="voiceChannel">Voice Channel To Delete</param>
/// <param name="beforeCondition">Condition to delete</param>
/// <returns>Task</returns>
public static async Task DeleteVoiceChannel(SocketVoiceChannel voiceChannel, Func<bool> beforeCondition = null)
{
if (beforeCondition is not null)
{
if (!beforeCondition())
return;
}
_ = voiceChannel.DeleteAsync();
}
/// <summary>
/// Delete a voice channel searching by name if the condition is true or null
/// </summary>
/// <param name="voiceChannelName">Channel Name to Search</param>
/// <param name="beforeCondition">Condition</param>
/// <returns>Task</returns>
public async Task DeleteVoiceChannel(string voiceChannelName, Func<bool> beforeCondition = null)
{
SocketVoiceChannel voiceChannel = GetVoiceChannelByName(voiceChannelName);
if (voiceChannel is null)
return;
_ = DeleteVoiceChannel(voiceChannel, beforeCondition);
}
/// <summary>
/// Delete the voice channels that the bot created for the mod (Except the main one)
/// </summary>
/// <returns>Task</returns>
public async Task CloseVoiceChat()
{
SocketVoiceChannel[] voiceChannels = Guild.VoiceChannels
.Where(c => c.Category.Name == Mod.Config.Bot.VoiceChatsCategoryName)
.Where(c => c.Name != Mod.Config.Bot.MainVoiceChatName)
.ToArray();
foreach (SocketVoiceChannel voiceChannel in voiceChannels)
{
await DeleteVoiceChannel(voiceChannel);
}
}
}
}