public HoundBot() { _discordClient = new DiscordSocketClient(new DiscordSocketConfig { LogLevel = LogSeverity.Warning, MessageCacheSize = 200 }); _commandService = new CommandService(new CommandServiceConfig { CaseSensitiveCommands = false, LogLevel = LogSeverity.Warning, DefaultRunMode = RunMode.Sync }); var builder = new ConfigurationBuilder() .SetBasePath(AppContext.BaseDirectory) .AddJsonFile("config.json", false, true); var configuration = builder.Build(); _config = configuration.Get <Config>(); var starboardService = new StarboardService(_discordClient, _config); _services = new ServiceCollection() .AddSingleton(_discordClient) .AddSingleton(_commandService) .AddSingleton(_config) .AddSingleton(starboardService) .AddSingleton <QuoteService>() .AddSingleton <CommandHandlingService>() .BuildServiceProvider(); }
private static async Task Bot_ReactionRemoved( Cacheable <IUserMessage, ulong> arg1, ISocketMessageChannel arg2, SocketReaction arg3) { DogStatsd.Increment("messages.reactions.removed"); IUser usr; if (!arg3.User.IsSpecified) { return; } else { usr = arg3.User.Value; } if (usr.IsBot || usr.IsWebhook) { return; } var message = await arg1.GetOrDownloadAsync() .ConfigureAwait(false); await StarboardService.ExecuteRemovalAsync(message, usr.Id) .ConfigureAwait(false); }
public static async Task MessageReactionAddedEventHandlerAsync(TheGodfatherBot bot, MessageReactionAddEventArgs e) { if (e.Guild is null || e.Channel is null || e.Message is null) { return; } StarboardService ss = bot.Services.GetRequiredService <StarboardService>(); if (ss.IsStarboardEnabled(e.Guild.Id, out ulong cid, out string star) && cid != e.Channel.Id && e.Emoji.GetDiscordName() == star) { LogExt.Debug(bot.GetId(e.Guild.Id), "Reacted with star emoji: Message {MessageId}, {Guild}", e.Message.Id, e.Guild); ss.RegisterModifiedMessage(e.Guild.Id, e.Channel.Id, e.Message.Id); } ReactionRoleService rrs = bot.Services.GetRequiredService <ReactionRoleService>(); ReactionRole? rr = await rrs.GetAsync(e.Guild.Id, e.Emoji.GetDiscordName()); if (rr is { })
public CommandHandler(IServiceProvider provider, DiscordSocketClient client, CommandService commandService, AfkService afkService, RatelimitingService ratelimitingService, StarboardService starboardService, SelfAssignableRolesService selfService, AnnouncementService announcementService, ModService modService, GuildCountUpdaterService guildUpdate, ExpService expService, BanService banService, InteractionsService interactionsService) { _client = client; _commands = commandService; _afkService = afkService; _services = provider; _ratelimitingService = ratelimitingService; _starboardService = starboardService; _selfAssignableRolesService = selfService; _announcementService = announcementService; _modService = modService; _guildCount = guildUpdate; _banService = banService; _interactionsService = interactionsService; _guildCount.Initialize(client.ShardId, Utility.TOTAL_SHARDS, client.Guilds.Count); _client.MessageReceived += HandleCommandsAsync; //_client.MessageReceived += _afkService.Client_MessageReceived; _commands.Log += CommandsOnLog; _client.JoinedGuild += ClientOnJoinedGuild; _client.LeftGuild += ClientOnLeftGuild; _client.MessageReceived += expService.IncreaseEpOnMessageReceive; _client.ReactionAdded += _starboardService.ClientOnReactionAdded; _client.ReactionRemoved += _starboardService.ClientOnReactionRemoved; _client.UserJoined += _selfAssignableRolesService.ClientOnUserJoined; _client.UserJoined += _announcementService.ClientOnUserJoined; _client.UserLeft += _announcementService.ClientOnUserLeft; //mod Service _client.UserBanned += _modService.ClientOnUserBanned; _client.UserUnbanned += _modService.ClientOnUserUnbanned; }
private static async Task Bot_ReactionAdded( Cacheable <IUserMessage, ulong> arg1, ISocketMessageChannel arg2, SocketReaction arg3) { DogStatsd.Increment("messages.reactions.added"); IUser usr; var msg = await arg1.GetOrDownloadAsync().ConfigureAwait(false); if (msg == null) { return; } if (!arg3.User.IsSpecified) { return; } else { usr = arg3.User.Value; } if (usr.IsBot || usr.IsWebhook) { return; } if (arg2 is IGuildChannel) { await PinningService.ExecuteAdditionAsync(SkuldApp.DiscordClient, SkuldApp.Configuration, msg, arg2) .ConfigureAwait(false); await StarboardService.ExecuteAdditionAsync(msg, arg2, arg3) .ConfigureAwait(false); } if (arg2.Id == SkuldApp.Configuration.IssueChannel) { using var Database = new SkuldDbContextFactory() .CreateDbContext(); var user = await Database.InsertOrGetUserAsync(usr) .ConfigureAwait(false); if (user.Flags.IsBitSet(DiscordUtilities.BotCreator)) { try { if (arg1.HasValue) { var message = Database.Issues .FirstOrDefault(x => x.IssueChannelMessageId == arg1.Id ); if (message != null) { var emote = arg3.Emote as Emote; if (emote.Id == DiscordUtilities.Tick_Emote.Id) { if (!message.HasSent) { try { var newissue = new NewIssue(message.Title) { Body = message.Body }; newissue. Assignees.Add("exsersewo"); newissue. Labels.Add("From Command"); var issue = await SkuldApp .Services .GetRequiredService <GitHubClient>() .Issue .Create( SkuldApp .Configuration .GithubRepository, newissue ).ConfigureAwait(false); try { await SkuldApp.DiscordClient .GetUser( message.SubmitterId ) .SendMessageAsync( "", false, new EmbedBuilder() .WithTitle( "Good News!" ) .AddAuthor( SkuldApp .DiscordClient ) .WithDescription( "Your issue:\n" + $"\"[{newissue.Title}]" + $"({issue.HtmlUrl})\"" + "\n\nhas been accepted" ) .WithRandomColor() .Build() ).ConfigureAwait(false); } catch { } await msg.ModifyAsync(x => { x.Embed = msg.Embeds .ElementAt(0) .ToEmbedBuilder() .AddField( "Sent", DiscordUtilities .Tick_Emote .ToString() ) .Build(); }).ConfigureAwait(false); message.HasSent = true; await Database.SaveChangesAsync() .ConfigureAwait(false); } catch (Exception ex) { Log.Error( "Git-" + SkuldAppContext.GetCaller(), ex.Message, null, ex ); } } } else if ( emote.Id == DiscordUtilities.Cross_Emote.Id ) { Database.Issues.Remove(message); await Database.SaveChangesAsync() .ConfigureAwait(false); await msg.DeleteAsync() .ConfigureAwait(false); try { await SkuldApp .DiscordClient .GetUser(message.SubmitterId) .SendMessageAsync( "", false, new EmbedBuilder() .WithTitle("Bad News") .AddAuthor( SkuldApp.DiscordClient ) .WithDescription( "Your issue:\n" + $"\"{message.Title}\"" + "\n\nhas been declined. " + "If you would like to know why, " + $"send: {usr.FullName()} a message" ) .WithRandomColor() .Build() ).ConfigureAwait(false); } catch { } } } } } catch (Exception ex) { Log.Critical(Key, ex.Message, null, ex ); } } } }