// Receive strings from main client with relevant metadata // Name | Channel | Role | Emoji // "Test Channel 1 | <#537460056979931151> | <@&662770161425842246> | <:fifty:587768727723048981>" public static string RefreshChannelList(List <string> configInputs) { string msg = ""; ChannelList = new List <ChannelSelector>(); foreach (var input in configInputs) { // Verify input if (!InputMessageFormatValid(input)) { continue; } var inputs = input.Split(" | "); // Extract input information var newEntry = new ChannelSelector(); try { var name = inputs[0]; var channelId = Convert.ToUInt64(GetNumbersFromString(inputs[1])); var roleId = Convert.ToUInt64(GetNumbersFromString(inputs[2])); var emojiId = Convert.ToUInt64(GetNumbersFromString(inputs[3])); // Validate if (!PneumaBotClient.ValidateChannelId(channelId)) { throw new PneumaBotExceptions("Channel not in this server."); } if (!PneumaBotClient.ValidateRoldId(roleId)) { throw new PneumaBotExceptions("Role not in this server."); } if (!PneumaBotClient.ValidateEmojiId(emojiId)) { throw new PneumaBotExceptions("Emoji not in this server."); } newEntry.Name = name; newEntry.ChannelId = channelId; newEntry.RoleId = roleId; newEntry.EmojiId = emojiId; } catch (Exception e) { msg += $"ERROR when processing: {input}\n{e.Message}\n"; continue; } // Add to list ChannelList.Add(newEntry); } return(msg + "Channel List Refreshed"); }
public async Task MainAsync() { var clientConfig = new DiscordSocketConfig(); clientConfig.AlwaysDownloadUsers = true; _client = new DiscordSocketClient(clientConfig); _client.Log += Log; _client.MessageReceived += PneumaBotClient.OnMsgReceived; _client.ReactionAdded += PneumaBotClient.OnChannelConfigurationReactionAdded; _client.ReactionRemoved += PneumaBotClient.OnChannelConfigurationReactionRemoved; await _client.LoginAsync(TokenType.Bot, PneumaBotClient.TOKEN); await _client.StartAsync(); await Task.Delay(5000); PneumaBotClient.GetChannels(_client); await PneumaBotClient.RefreshChannelConfiguration(); await Task.Delay(-1); }