private async Task Client_GuildUpdated(Discord.WebSocket.SocketGuild arg1, Discord.WebSocket.SocketGuild arg2) { if (arg1.Name != arg2.Name) { using (MikiContext context = new MikiContext()) { GuildUser g = await context.GuildUsers.FindAsync(arg1.Id.ToDbLong()); g.Name = arg2.Name; await context.SaveChangesAsync(); } } }
/// <summary> /// Gets the name of a channel by it's ID. /// </summary> /// <param name="guild"></param> /// <param name="channelid">The ID of the channel to look up.</param> /// <returns></returns> public static string GetChannelName(Discord.WebSocket.SocketGuild guild, ulong channelid) { string ret = ""; foreach (Discord.WebSocket.SocketGuildChannel sgc in guild.Channels) { //sb.AppendLine(string.Format("Guild: {0}\tChannel ID: {1}\tChannel name: {2}", sgc.Guild.Name, sgc.Id.ToString(), sgc.Name)); if (sgc.Id == channelid) { ret = sgc.Name; } } return(ret); }
public static bool CheckOneRole(Discord.WebSocket.SocketGuild guild, string roleName) { var sameNameRoles = guild.Roles.Where(x => x.Name == roleName); if (sameNameRoles.Count() == 0) { Console.WriteLine($"Missing role: {roleName}."); return(false); } if (sameNameRoles.Count() > 2) { throw new GuildStructureException($"The guild {guild.Name} has role {roleName} twice or more. Please fix this outside of the bot."); } return(true); }
public async Task newGame([Remainder] string inputMessage = "") { if (Context.IsPrivate) { if (stdClassCSharp.readJsonFile("usersIds.json")["users"][Context.User.Id.ToString(), TiposDevolver.Boleano]) { if (string.IsNullOrEmpty(inputMessage)) { //await Context.User.SendMessageAsync($"tu id es: {Context.User.Id}"); await Context.User.SendMessageAsync($"para mandarme un juego es necesario me mandes un mensaje con el mismo comando con los siguientes datos separados por renglones:{Environment.NewLine}" + $"Titulo: titulo del juego{Environment.NewLine}Descripcion: descripcion o genero del juego{Environment.NewLine}UploadBy o Uploader: quien sube el juego{Environment.NewLine}ImagenDiscord: url de la imagen del uploader{Environment.NewLine}ImagenJuego: url de la imagen del juego" + $"{Environment.NewLine}Peso: tamaño que tiene el juego{Environment.NewLine}Formato: formato del juego{Environment.NewLine}Password: password del juego{Environment.NewLine}Links:{Environment.NewLine}poner todos los links del juego{Environment.NewLine}{Environment.NewLine}" + $"Version o updateVersion: versión del update(Importante dejar por lo menos un renglon en blanco para ubicar cuando terminan los links del juego){Environment.NewLine}Peso: tamaño del update" + $"{Environment.NewLine}Formato: formato del update{Environment.NewLine}Links: aqui todos los links del update{Environment.NewLine}{Environment.NewLine}" + $"Peso: tamaño del dlc(Es importante dejar por lo menos un renglon para ubicar cuando terminan los links del update){Environment.NewLine}Formato: formato del dlc{Environment.NewLine}Links:{Environment.NewLine}links del dlc{Environment.NewLine}{Environment.NewLine}{Environment.NewLine}" + $"No es importante capturar los datos en orden a excepción de links que es el que define el final de juego, update o dlc. Hay datos del juego que se pueden omitirse para capturar pero para el juego es importante capturar titulo y links, en update version y links, en dlc solo capturar links.{Environment.NewLine}De lo contrario no se toamrá en cuenta el apartado correspondiente"); } else { Discord.WebSocket.SocketGuild switchGeneral = Context.Client.GetGuild(485262131797688331); string anuncio = ""; string response = Utils.guardarJuego(inputMessage, ref anuncio); await Context.User.SendMessageAsync($"{Context.User.Mention} {response}"); anuncio = /*switchGeneral.EveryoneRole.Mention + */ "@everyone " + anuncio; if (!string.IsNullOrWhiteSpace(anuncio)) { //await Context.Client.GetGuild(485262131797688331).GetTextChannel(485446685552803850).SendMessageAsync(anuncioC); await switchGeneral.GetTextChannel(485446685552803850).SendMessageAsync(anuncio); } } } else { await Context.User.SendMessageAsync($"No estas autorizado para utilizar este comando"); } } else { await Context.Message.DeleteAsync(RequestOptions.Default); await Context.Channel.SendMessageAsync($"Ese comando solo funciona por mp."); } }
/// <summary> /// Creates all the roles that the bot needs and which have not been created manually yet. /// </summary> /// <param name="guild">The guild where we check the roles.</param> public static async Task CreateMissingRoles(Discord.WebSocket.SocketGuild guild) { // First add spectral metal roles, then spectral digit roles. foreach (string roleName in Ranking.SpectralMetalRoles) { var sameNameRole = guild.Roles.FirstOrDefault(x => x.Name == roleName); if (sameNameRole == null) { System.Console.WriteLine("Creating the missing role " + roleName); await guild.CreateRoleAsync(name : roleName, color : Settings.roleColor(roleName), isMentionable : false); } } foreach (string roleName in Ranking.SpectralDigitRoles) { var sameNameRole = guild.Roles.FirstOrDefault(x => x.Name == roleName); if (sameNameRole == null) { System.Console.WriteLine("Creating the missing role " + roleName); await guild.CreateRoleAsync(name : roleName, color : Settings.roleColor(roleName), isMentionable : false); } } // In the ordering, then come big loud roles and tiny loud roles. foreach (string roleName in Ranking.LoudMetalRoles) { var sameNameRole = guild.Roles.FirstOrDefault(x => x.Name == roleName); if (sameNameRole == null) { System.Console.WriteLine("Creating the missing role " + roleName); await guild.CreateRoleAsync(name : roleName, color : Settings.roleColor(roleName), isMentionable : false); } } foreach (string roleName in Ranking.LoudDigitRoles) { var sameNameRole = guild.Roles.FirstOrDefault(x => x.Name == roleName); if (sameNameRole == null) { System.Console.WriteLine("Creating the missing role " + roleName); await guild.CreateRoleAsync(name : roleName, color : Settings.roleColor(roleName), isMentionable : false); } } }
public static bool CheckAllRoles(Discord.WebSocket.SocketGuild guild) { bool allRolesPresent = true; foreach (string roleName in Ranking.SpectralMetalRoles) { bool check = CheckOneRole(guild, roleName); if (!check) { allRolesPresent = false; } } foreach (string roleName in Ranking.SpectralDigitRoles) { bool check = CheckOneRole(guild, roleName); if (!check) { allRolesPresent = false; } } foreach (string roleName in Ranking.LoudMetalRoles) { bool check = CheckOneRole(guild, roleName); if (!check) { allRolesPresent = false; } } foreach (string roleName in Ranking.LoudDigitRoles) { bool check = CheckOneRole(guild, roleName); if (!check) { allRolesPresent = false; } } return(allRolesPresent); }
public static async System.Threading.Tasks.Task LogExceptionToDiscordChannel(Exception exception, string messageContent, string?guild = null, string?user = null) { // Get Settings - check if both bot server and exception channel is given Settings settings = Settings.Load(); if (!string.IsNullOrWhiteSpace(settings?.BotDiscordServer) && !string.IsNullOrWhiteSpace(settings?.BotLogExceptionsChannel)) { // Get the guild Discord.WebSocket.SocketGuild kupoNutsGuild = Program.DiscordClient.GetGuild(ulong.Parse(settings.BotDiscordServer)); if (kupoNutsGuild == null) { throw new Exception("Unable to access guild"); } // Post message string exceptionMessage = $"Server: {guild ?? "Unknown"}\nUser: {user ?? "Unknown"}\nMessage: {messageContent}.\n`{exception}`"; await kupoNutsGuild.GetTextChannel(ulong.Parse(settings.BotLogExceptionsChannel)).SendMessageAsync(exceptionMessage); } }
/// <summary> /// Gets a list of the Guilds channels and stores them in a Static Hashtable. /// </summary> /// <param name="guild"></param> /// <returns>True if successful, otherwise False.</returns> public static bool CacheOurChannels(Discord.WebSocket.SocketGuild guild) { Globals.GUILDCHANNELSBYID = new System.Collections.Hashtable(); Globals.GUILDCHANNELSBYNAME = new System.Collections.Hashtable(); try { foreach (Discord.WebSocket.SocketGuildChannel sgc in guild.Channels) { //sb.AppendLine(string.Format("Guild: {0}\tChannel ID: {1}\tChannel name: {2}", sgc.Guild.Name, sgc.Id.ToString(), sgc.Name)); Globals.GUILDCHANNELSBYID.Add(sgc.Id, sgc.Name); Globals.GUILDCHANNELSBYNAME.Add(sgc.Name, sgc.Id); } } catch (Exception ex) { Console.WriteLine(ex.Message); return(false); } return(true); }
private async Task Client_LeftGuild(Discord.WebSocket.SocketGuild arg) { DogStatsd.Increment("guilds.left"); DogStatsd.Counter("guilds", Bot.instance.Client.Guilds.Count); }
private async Task Client_LeftGuild(Discord.WebSocket.SocketGuild arg) { DogStatsd.Increment("guilds.left"); DogStatsd.Set("guilds", Bot.Instance.Guilds.Count, Bot.Instance.Guilds.Count); await Task.Yield(); }
public static RaceAnnouncer.Schema.Models.Guild Convert( this Discord.WebSocket.SocketGuild guild) => new Schema.Models.Guild( guild.Id , guild.Name);
public async Task editGame([Remainder] string inputMessage = "") { if (Context.IsPrivate) { if (stdClassCSharp.readJsonFile("usersIds.json")["users"][Context.User.Id.ToString(), TiposDevolver.Boleano]) { int indexGame = 0; if (string.IsNullOrEmpty(inputMessage)) { var builder = new EmbedBuilder(); int fields = 0; builder.WithTitle("Ids de los juegos:"); builder.WithColor(new Color(0xFFF000)); foreach (stdClassCSharp juego in Utils.getListGamesEdit()) { if (fields >= 24) { await Context.User.SendMessageAsync("", false, builder.Build()); builder = new EmbedBuilder(); builder.WithColor(new Color(0xFFF000)); fields = 0; } builder.AddField(juego["indexGame", TiposDevolver.Cadena], juego["Titulo"]); fields++; } if (fields >= 24) { await Context.User.SendMessageAsync("", false, builder.Build()); builder = new EmbedBuilder(); builder.WithColor(new Color(0xFFF000)); fields = 0; } builder.AddField("¿Para editar?", $"Solo vuelve a colocar el comando !edit_game [id del juego] en base a la lista colocada y te devolveré los datos del juego que se capturaron al agregarlo" + $" después de editar esos datos mandas de nuevo el comando pero ahora de la siguiente manera:{Environment.NewLine}{Environment.NewLine}!edit_game id: id del juego{Environment.NewLine}" + $"Anuncio que quieres que realice el en el discord para informar a los usuarios del cambio realizado(se puede dejar el renglon en blanco y no se enviará anuncio){Environment.NewLine}" + $"Aqui los datos del juego editados."); await Context.User.SendMessageAsync("", false, builder.Build()); } else if (int.TryParse(inputMessage, out indexGame)) { string response = Utils.searchGameToEdit(indexGame); await Context.User.SendMessageAsync(response); } else { Discord.WebSocket.SocketGuild switchGeneral = Context.Client.GetGuild(485262131797688331); ArrayList datosJuego = new ArrayList(inputMessage.Split('\n')); int.TryParse(datosJuego[0].ToString().Substring(datosJuego[0].ToString().IndexOf(':') + 1), out indexGame); string anuncio = datosJuego[1].ToString().Trim(); datosJuego.RemoveAt(0); datosJuego.RemoveAt(0); string response = string.Join("\n", datosJuego.ToArray()); response = Utils.guardarJuego(response, ref anuncio, indexGame); await Context.User.SendMessageAsync($"{Context.User.Mention} {response}"); if (!string.IsNullOrWhiteSpace(anuncio)) { await switchGeneral.GetTextChannel(485446685552803850).SendMessageAsync($"@everyone {anuncio}"); } } } else { await Context.User.SendMessageAsync("No estas autorizado para utilizar este comando"); } } else { await Context.Message.DeleteAsync(RequestOptions.Default); await Context.Channel.SendMessageAsync($"Ese comando solo funciona por mp."); } }