public void StartBotStatuses(DiscordSocketClient client) { _client = client; using (var uow = DBHandler.UnitOfWork()) { string status = uow.BotConfig.GetDefaultStatus(_client.CurrentUser.Id); bool rotation = uow.BotConfig.IsRotatingStatuses(_client.CurrentUser.Id); if (status != "" && !rotation) { _client.SetGameAsync(status); } if (rotation) { status = uow.BotStatuses.GetStatus().Status; _client.SetGameAsync(status); } } Statuses(); }
private async Task UserJoinedAsync(SocketGuildUser user) { var GuildUser = (IGuildUser)user; if (user.Guild == null) { return; } GreetMessages GM = null; AutoBan AB = null; ulong ChannelID = 0; using (var uow = DBHandler.UnitOfWork()) { if (!uow.Guild.IsGreeting(GuildUser.Guild.Id)) { return; } GM = uow.GreetMessages.GetRandomGreetMessage(GuildUser.Guild.Id); ChannelID = uow.Guild.GetOrCreateGuild(GuildUser.Guild.Id).GreetMessageChannel; AB = uow.AutoBan.GetAutoBan(GuildUser.Id); } if (AB != null) { await _discord.GetGuild(GuildUser.GuildId).AddBanAsync(user, reason: "Autobanned by Natsuki."); return; } if (GM == null || ChannelID == 0) { return; } var ChannelToSend = (IMessageChannel)_discord.GetChannel(ChannelID); string message = GM.Message.Replace("{user}", GuildUser.Mention); await ChannelToSend.SendMessageAsync(message); }
private async Task OnMessageAsync(SocketMessage s) { var msg = s as SocketUserMessage; if (msg == null) { return; } if (msg.Author.Id == _discord.CurrentUser.Id) { return; } var context = new SocketCommandContext(_discord, msg); //Get URL in string MatchCollection Matches = Regex.Matches(context.Message.Content, @"((http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)"); //Right first step //Check if the message has an image. If it doesn't and doesn't have a URL, we don't care. if (context.Message.Attachments.Count == 0 && Matches.Count == 0) { return; } //Now we fetch each part User U = null; Channels C = null; using (var uow = DBHandler.UnitOfWork()) { U = uow.User.GetOrCreateUser(context.User.Id); C = uow.Channels.GetOrCreateChannel(context.Channel.Id, DefaultCD); //Create just to make sure it exists so more doesn't fail down there uow.UserRate.GetOrCreateUserRate(C.ID, U.ID); } //Is the user exempt? if (U == null || U.IsExempt) { return; } //Now we need to check if the channel is even part of it all if (C == null || !C.State) { return; } //Alright we need to limit shit now. //Lets check if the user is allowed to post bool canPost = true; int UserPostsSinceLastTrack = 0; using (var uow = DBHandler.UnitOfWork()) { canPost = uow.UserRate.CanUserPostImages(C.ID, U.ID, C.CooldownTime, C.MaxPosts); UserPostsSinceLastTrack = uow.UserRate.GetPostsSinceLastTrack(C.ID, U.ID); } int amountToAdd = context.Message.Attachments.Count + Matches.Count; //If they can post we need to add one to their posts and then we're done here if (canPost && amountToAdd <= (C.MaxPosts - UserPostsSinceLastTrack)) { using (var uow = DBHandler.UnitOfWork()) { uow.UserRate.AddUserPost(C.ID, U.ID, amountToAdd); } return; } //If they can't post we have a lot to deal with here. //First we have to actually delete the message await context.Message.DeleteAsync(); //Then we need to tell the user not to post so quick var tellingOff = await context.Channel.SendErrorAsync("Slow down dummy!"); //Remove after 2 seconds tellingOff.DeleteAfter(5); }
private async Task DeletedAsync(Cacheable <IMessage, ulong> CacheableMessage, ISocketMessageChannel origChannel) { var CachedMessage = await CacheableMessage.GetOrDownloadAsync(); var MessageChannel = (ITextChannel)origChannel; if (CachedMessage.Source != MessageSource.User) { return; } if (MessageChannel.Guild == null) { return; } if (CachedMessage == null) { return; } Guild G = null; List <BlockedLogs> BLs = new List <BlockedLogs>(); using (var uow = DBHandler.UnitOfWork()) { if (!uow.Guild.IsDeleteLoggingEnabled(MessageChannel.Guild.Id)) { return; } G = uow.Guild.GetOrCreateGuild(MessageChannel.Guild.Id); if (G.GuildID == 0) { return; } BLs = uow.BlockedLogs.GetServerBlockedLogs(MessageChannel.Guild.Id); } if (BLs != null && BLs.Count > 0) { if (BLs.Any(x => CachedMessage.Content.StartsWith(x.BlockedString))) { return; } } if (G == null) { return; } var ChannelToSend = (IMessageChannel)_discord.GetChannel(G.DeleteLogChannel); string content = CachedMessage.Content; if (content == "") { content = "*original message was blank*"; } EmbedBuilder embed = new EmbedBuilder().WithAuthor(eab => eab.WithIconUrl(CachedMessage.Author.GetAvatarUrl()).WithName(CachedMessage.Author.Username)).WithOkColour() .AddField(efb => efb.WithName("Channel").WithValue("#" + origChannel.Name).WithIsInline(true)) .AddField(efb => efb.WithName("MessageID").WithValue(CachedMessage.Id).WithIsInline(true)) .AddField(efb => efb.WithName("UserID").WithValue(CachedMessage.Author.Id).WithIsInline(true)) .AddField(efb => efb.WithName("Message").WithValue(content)); string footerText = "Created: " + CachedMessage.CreatedAt.ToString(); if (CachedMessage.EditedTimestamp != null) { footerText += $" | Edited: " + CachedMessage.EditedTimestamp.ToString(); } EmbedFooterBuilder footer = new EmbedFooterBuilder().WithText(footerText); await ChannelToSend.BlankEmbedAsync(embed.WithFooter(footer)); if (CachedMessage.Attachments.Count == 0) { return; } foreach (var attatchment in CachedMessage.Attachments) { await ChannelToSend.SendMessageAsync($"Message ID: {CachedMessage.Id} has attachment: {attatchment.Url}"); } }