public Task MessageCreated(DSharpPlus.EventArgs.MessageCreateEventArgs e) { Console.ForegroundColor = ConsoleColor.White; Konsol.WriteLine(e.Message.Timestamp.ToString() + " -> Sunucu : " + e.Guild.Name + " -> Kanal : " + e.Channel.Name + " -> Kullanıcı : " + e.Author.Username + " -> Mesaj : " + e.Message.Content); return(Task.Delay(0)); }
private async Task DiscordClient_MessageCreatedAsync(DiscordClient client, DSharpPlus.EventArgs.MessageCreateEventArgs e) { if (e.Channel.IsPrivate == false) { try { EmojiCounterService emojiCounterService = new EmojiCounterService(); await emojiCounterService.CountEmojiInMessage(e.Message); } catch (Exception) { Console.WriteLine("Error: Counting emoji in new message."); } } }
public static async Task Discord_MessageCreated(DiscordClient sender, DSharpPlus.EventArgs.MessageCreateEventArgs messageArgs) { new Thread(async() => { var responses = ConfigValues.Responses.ToList(); if (responses.Select(response => response.trigger).Contains(messageArgs.Message.Content)) { Response response = responses.Find(r => r.trigger == messageArgs.Message.Content); if (response.allowedChannels == null || response.allowedChannels.Contains(messageArgs.Channel)) { await messageArgs.Message.RespondAsync(response.response); } } }).Start(); }
private Task Client_MessageCreated(DSharpPlus.EventArgs.MessageCreateEventArgs e) { Console.ForegroundColor = ConsoleColor.Yellow; Console.Write($"@{e.Author.Username} #{e.Channel.Name} in {e.Guild.Name}:"); Console.ForegroundColor = ConsoleColor.White; Console.Write($" {e.Message.Content}\n"); if (e.Message.MentionedUsers.Contains(client.CurrentUser)) { if (!SetupMode) { ProcessCommand(e.Message.Content, e, CommandTrigger.BotMentioned); } } else if (e.Message.Content.StartsWith(config.Prefix)) // We check if the message received starts with our bot's command prefix. If it does... { if (SetupMode) { string[] messageSplit = e.Message.Content.Split(' '); if (messageSplit.Length == 2) { if (messageSplit[0] == $"{config.Prefix}authenticate" && messageSplit[1].Trim() == AuthorizationCode) { //we've authenticated! SetupMode = false; AuthorizationCode = ""; config.OwnerID = e.Message.Author.Id.ToString(); config.WriteConfig(); e.Channel.SendMessageAsync($"I'm all yours, {e.Message.Author.Mention}~!"); commandManager.AddPermission(e.Message.Author, PermissionType.Owner); commandManager.WritePermissionsFile(); //Write the permissions file to the disk so she remembers who her owner is. InitCommands(); } } return(Task.Delay(0)); } // We move onto processing the command. // We pass in the MessageCreateEventArgs so we can get other information like channel, author, etc. The CommandsManager wants these things ProcessCommand(e.Message.Content, e, CommandTrigger.MessageCreate); } return(Task.Delay(0)); }
public static async Task CheckMessageClean(DSharpPlus.EventArgs.MessageCreateEventArgs args) { try { using var context = new BotContext(); var servers = context.Servers .Include(b => b.Users) .ToList(); Server server = new Server() { SettingsJson = "{ \"warnWords\": [], \"deleteWords\": []}", Users = new User[] { new User() { UserSnow = 0 } } }; foreach (Server s in servers) { if (s.ServerSnow == args.Guild.Id) { server = s; break; } } var users = server.Users; foreach (User u in users) { if (u.UserSnow == args.Author.Id) { if (u.Strikes >= 3) { await args.Message.DeleteAsync(); await args.Guild.Owner.SendMessageAsync($"User {args.Author.Username}#{args.Author.Discriminator} has just hit 3 strikes for time number {u.TotalMutes}. They're being auto-muted until you or an admin remove it."); u.Strikes = 0; } } } var settings = Setting.FromJson(server.SettingsJson); foreach (string word in settings.WarnWords) { if (args.Message.Content.Contains(word)) { await args.Message.RespondAsync("Hey now, that's not allowed here. I'm gonna give you a warning for now. Three warnings will give a temporary mute, so be careful!"); foreach (User u in server.Users) { if (u.UserSnow == args.Author.Id) { ++u.Strikes; if (u.Strikes >= 3) { await args.Message.DeleteAsync(); await args.Guild.Owner.SendMessageAsync($"User {args.Author.Username}#{args.Author.Discriminator} has just hit 3 strikes for time number {u.TotalMutes}d. They're being auto-muted until you or an admin remove it."); u.Strikes = 0; } } } break; } } foreach (string word in settings.DeleteWords) { if (args.Message.Content.Contains(word)) { await args.Message.RespondAsync("Wow, that was too much for me to just warn you, that's getting deleted, and the owner of the server will be notified as well."); await args.Message.DeleteAsync($"Language: {word}"); await args.Guild.Owner.SendMessageAsync($"Message deleted in channel #{args.Channel.Name}"); } } await context.SaveChangesAsync(); } catch (System.Exception e) { System.Console.WriteLine(e.InnerException); throw; } }