public async Task UserJoined(SocketGuildUser user) { // Locate TownGuild in the database var guild = database.GetGuild(user.Guild); if (guild != null) { // TextChannel where Notifications go var NotificationChannel = user.Guild.GetTextChannel(guild.NotificationChannel); //Not the most elegant, but can't afford to spend more time on it right now await WelcomeModule.SendTo(user); // Send welcome message, parsing the welcome message string from the TownGuild property if (guild.WelcomeMessage != "") { var welcome = await NotificationChannel.SendMessageAsync(guild.ParseMessage(user, discord)); await welcome.AddReactionAsync(new Emoji("👋")); } if (guild.MilestoneMessage != "" && (user.Guild.Users.Count % guild.MilestoneMarker) == 0) { await NotificationChannel.SendMessageAsync($"We've now hit {user.Guild.Users.Count} members! Wooooo!"); await Task.Delay(1000 * 20); await NotificationChannel.SendMessageAsync($"Partaayyy!"); } } }
async Task MessageReceived(SocketMessage rawMessage) { // Ignore system messages and messages from bots if (!(rawMessage is SocketUserMessage message)) { return; } if (message.Source != MessageSource.User) { return; } var context = new SocketCommandContext(discord, message); var guild = (context.Guild == null) ? null : database.GetGuild(context.Guild); int argPos = 0; if (guild == null && !message.HasMentionPrefix(discord.CurrentUser, ref argPos)) { return; } if (guild != null && !message.HasStringPrefix(guild.Prefix, ref argPos) && !message.HasMentionPrefix(discord.CurrentUser, ref argPos)) { return; } var result = await commands.ExecuteAsync(context, argPos, provider); if (result.Error.HasValue && (result.Error.Value != CommandError.UnknownCommand)) { Console.WriteLine(result.Error + "\n" + result.ErrorReason); } }
public async Task Process(SocketMessage message) { if (message.MentionedRoles.Count == 0) { return; } ITextChannel channel = message.Channel as ITextChannel; if (channel == null) { return; } TownGuild guild = database.GetGuild(channel.Guild); if (guild == null) { return; } foreach (CrossAlert crossAlert in guild.CrossAlerts .Where(x => x.Channel != channel.Id) .Where(x => message.MentionedRoles.Any(role => role.Id == x.Role))) { ITextChannel targetChannel = await channel.Guild.GetTextChannelAsync(crossAlert.Channel); IUserMessage response = await targetChannel.SendMessageAsync(message.Author.Mention + " in " + channel.Mention + ": " + message.Content); await response.AddReactionAsync(new Emoji("✔")); } }
async Task Search(SocketMessage message) { ITextChannel channel = message.Channel as ITextChannel; if (channel == null) { return; } TownGuild guild = database.GetGuild(channel.Guild); if (guild == null) { return; } await ShowWiki(message, guild); }
async Task Handle(SocketMessage socketMessage) { if (!(socketMessage is SocketUserMessage message && message.Channel is ITextChannel channel) || message.Author.Id == discord.CurrentUser.Id) { return; } TownGuild guild = database.GetGuild(channel.Guild); if (guild == null) { return; } ChannelFilter filter = guild.ChannelFilters.FirstOrDefault(x => x.Channel == channel.Id); if (filter == null) { return; } try { switch (filter.Type) { case ChannelFilter.FilterType.Heading: await FilterHeadings(filter, message); break; case ChannelFilter.FilterType.Image: await FilterScreenshots(filter, message); break; } } catch (Exception e) { Console.WriteLine(e.StackTrace); } }