public void GetUpdateDiscord() { TestWrapper(async(MixerConnection connection) => { ChannelModel channel = await ChannelsServiceUnitTests.GetChannel(connection); DiscordBotModel discord = await connection.Channels.GetDiscord(channel); Assert.IsNotNull(discord); Assert.IsTrue(discord.id > 0); IEnumerable <DiscordChannelModel> channels = await connection.Channels.GetDiscordChannels(channel); Assert.IsNotNull(channels); Assert.IsTrue(channels.Count() > 0); IEnumerable <DiscordRoleModel> roles = await connection.Channels.GetDiscordRoles(channel); Assert.IsNotNull(roles); Assert.IsTrue(roles.Count() > 0); discord = await connection.Channels.UpdateDiscord(channel, discord); Assert.IsNotNull(discord); Assert.IsTrue(discord.id > 0); }); }
private void ExecuteDeleteBotCommand( DiscordBotModel parameter) { var model = this.Config.DiscordBotList; if (parameter == null) { return; } if (model.Contains(parameter)) { var selectIndex = model.IndexOf(parameter) - 1; if (selectIndex < 0) { selectIndex = 0; } model.Remove(parameter); if (model.Count > 0) { this.ChangeSelectedBotCallback?.Invoke( model[selectIndex]); } } }
public override void Initialize() { messageModel = new MessageModel() { content = "", }; Commands.ChatCommands.Add(new Command("config.reload.permission", OnReloadConfig, "reloadconfig", "rcfg") { HelpText = "Reloads the configuration file for Discord Announcer." }); string configPath = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory() + @"\").FullName, "DiscordAnnouncer.json"); if (!File.Exists(configPath)) { File.WriteAllText(configPath, JsonConvert.SerializeObject(new DiscordBotModel() { EnableAnnouncer = true, WebhookToken = "TOKEN_HERE", WebhookID = 0 }, Formatting.Indented)); } try { botInfo = JsonConvert.DeserializeObject <DiscordBotModel>(File.ReadAllText(configPath)); ServerApi.Hooks.ServerJoin.Register(this, OnPlayerJoin); ServerApi.Hooks.ServerLeave.Register(this, OnPlayerLeave); ServerApi.Hooks.ServerBroadcast.Register(this, OnServerBroadcast); } catch (FileNotFoundException) { Console.Write("Could not find config file 'DiscordAnnouncer.json'"); } }
private void ExecuteAddBotCommand() { var model = this.Config.DiscordBotList; var item = new DiscordBotModel() { Name = "Bot " + (model.Count + 1) }; model.Add(item); this.ChangeSelectedBotCallback?.Invoke(item); }
public void OnReloadConfig(CommandArgs args) { try { string configPath = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory() + @"\").FullName, "DiscordAnnouncer.json"); if (!File.Exists(configPath)) { File.WriteAllText(configPath, JsonConvert.SerializeObject(new DiscordBotModel() { EnableAnnouncer = true, WebhookToken = "TOKEN_HERE", WebhookID = 0 }, Formatting.Indented)); } botInfo = JsonConvert.DeserializeObject <DiscordBotModel>(File.ReadAllText(configPath)); Console.Write("DiscordAnnouncer config file reloaded successfully."); } catch { Console.WriteLine("Could not reload DiscordAnnouncer config file."); } }
/// <summary> /// Updates the Discrd bot information for the specified channel. /// </summary> /// <param name="channel">The channel to update discord bot information for</param> /// <param name="discord">The Discord bot information</param> /// <returns>The updated Discord bot information</returns> public async Task <DiscordBotModel> UpdateDiscord(ChannelModel channel, DiscordBotModel discord) { Validator.ValidateVariable(channel, "channel"); Validator.ValidateVariable(discord, "discord"); return(await this.PutAsync <DiscordBotModel>("channels/" + channel.id + "/discord", this.CreateContentFromObject(discord))); }