private async Task Client_JoinedGuild(IDiscordGuild arg) { using (var scope = MikiApp.Instance.Services.CreateScope()) { var context = scope.ServiceProvider.GetService <DbContext>(); IDiscordChannel defaultChannel = await arg.GetDefaultChannelAsync(); if (defaultChannel != null) { LocaleInstance i = await Locale.GetLanguageInstanceAsync(context, defaultChannel.Id); (defaultChannel as IDiscordTextChannel).QueueMessage(i.GetString("miki_join_message")); } List <string> allArgs = new List <string>(); List <object> allParams = new List <object>(); List <object> allExpParams = new List <object>(); try { var members = await arg.GetMembersAsync(); for (int i = 0; i < members.Length; i++) { allArgs.Add($"(@p{i * 2}, @p{i * 2 + 1})"); allParams.Add(members.ElementAt(i).Id.ToDbLong()); allParams.Add(members.ElementAt(i).Username); allExpParams.Add(arg.Id.ToDbLong()); allExpParams.Add(members.ElementAt(i).Id.ToDbLong()); } await context.Database.ExecuteSqlCommandAsync( $"INSERT INTO dbo.\"Users\" (\"Id\", \"Name\") VALUES {string.Join(",", allArgs)} ON CONFLICT DO NOTHING", allParams); await context.Database.ExecuteSqlCommandAsync( $"INSERT INTO dbo.\"LocalExperience\" (\"ServerId\", \"UserId\") VALUES {string.Join(",", allArgs)} ON CONFLICT DO NOTHING", allExpParams); await context.SaveChangesAsync(); } catch (Exception e) { Log.Error(e.ToString()); } DogStatsd.Increment("guilds.joined"); } }
private async Task Client_JoinedGuild(IDiscordGuild arg) { IDiscordChannel defaultChannel = await arg.GetDefaultChannelAsync(); if (defaultChannel != null) { using (var context = new MikiContext()) { LocaleInstance i = await Locale.GetLanguageInstanceAsync(context, defaultChannel.Id); (defaultChannel as IDiscordTextChannel).QueueMessage(i.GetString("miki_join_message")); } } //List<string> allArgs = new List<string>(); //List<object> allParams = new List<object>(); //List<object> allExpParams = new List<object>(); //try //{ // for (int i = 0; i < arg.Members.Count; i++) // { // allArgs.Add($"(@p{i * 2}, @p{i * 2 + 1})"); // allParams.Add(arg.Members.ElementAt(i).Id.ToDbLong()); // allParams.Add(arg.Members.ElementAt(i).Username); // allExpParams.Add(arg.Id.ToDbLong()); // allExpParams.Add(arg.Members.ElementAt(i).Id.ToDbLong()); // } // using (var context = new MikiContext()) // { // await context.Database.ExecuteSqlCommandAsync( // $"INSERT INTO dbo.\"Users\" (\"Id\", \"Name\") VALUES {string.Join(",", allArgs)} ON CONFLICT DO NOTHING", allParams); // await context.Database.ExecuteSqlCommandAsync( // $"INSERT INTO dbo.\"LocalExperience\" (\"ServerId\", \"UserId\") VALUES {string.Join(",", allArgs)} ON CONFLICT DO NOTHING", allExpParams); // await context.SaveChangesAsync(); // } //} //catch (Exception e) //{ // Log.Error(e.ToString()); //} DogStatsd.Increment("guilds.joined"); }
private async Task Client_JoinedGuild(IDiscordGuild arg) { IDiscordChannel defaultChannel = await arg.GetDefaultChannelAsync(); defaultChannel.QueueMessageAsync(Locale.GetString(defaultChannel.Id, "miki_join_message")); List <string> allArgs = new List <string>(); List <object> allParams = new List <object>(); List <object> allExpParams = new List <object>(); try { var users = await arg.GetUsersAsync(); for (int i = 0; i < users.Count; i++) { allArgs.Add($"(@p{i * 2}, @p{i * 2 + 1})"); allParams.Add(users.ElementAt(i).Id.ToDbLong()); allParams.Add(users.ElementAt(i).Username); allExpParams.Add((await users.ElementAt(i).GetGuildAsync()).Id.ToDbLong()); allExpParams.Add(users.ElementAt(i).Id.ToDbLong()); } using (var context = new MikiContext()) { await context.Database.ExecuteSqlCommandAsync( $"INSERT INTO dbo.\"Users\" (\"Id\", \"Name\") VALUES {string.Join(",", allArgs)} ON CONFLICT DO NOTHING", allParams); await context.Database.ExecuteSqlCommandAsync( $"INSERT INTO dbo.\"LocalExperience\" (\"ServerId\", \"UserId\") VALUES {string.Join(",", allArgs)} ON CONFLICT DO NOTHING", allExpParams); await context.SaveChangesAsync(); } } catch (Exception e) { Log.Error(e.ToString()); } DogStatsd.Increment("guilds.joined"); // DogStatsd.Set("guilds", Bot.Instance.Client.Guilds.Count, Bot.Instance.Client.Guilds.Count); }