private void sendMsgBtn_Click(object sender, EventArgs e) { SocketTextChannel channel = textChannels.ToArray()[textChannelCBox.SelectedIndex]; if (!embedChk.Checked) { channel.SendMessageAsync(messageTxt.Text); } else { ServerConfig config = ServerConfigs.GetConfig(channel.Guild); EmbedBuilder embed = new EmbedBuilder(); embed.WithColor(config.EmbedColorRed, config.EmbedColorGreen, config.EmbedColorBlue); if (titleTxt.Text != "") { embed.WithTitle(titleTxt.Text); } if (config.FooterText != "") { embed.WithFooter(config.FooterText); } embed.WithDescription(messageTxt.Text); if (config.TimeStamp) { embed.WithCurrentTimestamp(); } embed.WithThumbnailUrl(config.IconURL); //Console.WriteLine(DateTime.Now + " | " + title + " |\n" + msg); Console.WriteLine(DateTime.Now + " | Sent server message using GUI in " + channel.Guild.Name + "/" + channel.Name); channel.SendMessageAsync("", false, embed.Build()); } respLbl.Text = "Ready"; }
public async Task AFKChannel([Remainder] string chanName) { IReadOnlyCollection <SocketVoiceChannel> vChans = Context.Guild.VoiceChannels; SocketVoiceChannel selectedChan = null; foreach (SocketVoiceChannel chan in vChans) { if (chan.Name.ToLower() == chanName.ToLower()) { selectedChan = chan; break; } } if (selectedChan == null) { await Context.Channel.SendMessageAsync("Voice channel does not exist! Make sure you type it out correctly!\n(not case sensitive)"); } ServerConfig config = ServerConfigs.GetConfig(Context.Guild); config.AFKChannelID = selectedChan.Id; config.AFKChannelName = selectedChan.Name; await Context.Guild.ModifyAsync(m => { m.AfkChannel = selectedChan; }); ServerConfigs.UpdateServerConfig(Context.Guild, config); await PrintEmbedMessage("AFK Channel Set", string.Format("**{0}** is now the AFK Channel!\nUsers will be sent there after **{1}mins**", selectedChan.Name, config.AFKTimeout / 60), iconUrl : config.IconURL); }
public async Task Timestamp(string text) { ServerConfig config = ServerConfigs.GetConfig(Context.Guild); if (text == null || text == "") { await Context.Channel.SendMessageAsync(string.Format("Usage: {0}timestamp <true|false>", config.Prefix)); } else { if (text.ToLower().Contains("enable") || text.ToLower().Contains("yes") || text.ToLower().Contains("on")) { text = "true"; } if (text.ToLower().Contains("disable") || text.ToLower().Contains("no") || text.ToLower().Contains("off")) { text = "false"; } } bool b = false; bool result = false; result = bool.TryParse(text, out b); if (result) { config.TimeStamp = b; } else { await Context.Channel.SendMessageAsync(string.Format("Usage: {0}timestamp <true|false>", config.Prefix)); } ServerConfigs.UpdateServerConfig(Context.Guild, config); await PrintEmbedMessage("Timestamp Configured", string.Format("Timestamp for embed set to **{0}**", text), iconUrl : config.IconURL); }
public async Task ServerStats() { int memberCount = Context.Guild.MemberCount; DateTimeOffset date = Context.Guild.CreatedAt; string name = Context.Guild.Name; string owner = Context.Guild.Owner.Username; ServerConfig serverConfig = ServerConfigs.GetConfig(Context.Guild); bool reqV = serverConfig.RequiresVerification; string verification = string.Format("\nRequires Verification: **{0}**", reqV); if (reqV) { SocketRole vRole = Context.Guild.GetRole(serverConfig.VerificationRoleID); verification += string.Format("\nVerified Role: **{0}**", vRole.Name); } string configs = "\nBot Prefix: **" + serverConfig.Prefix + "**" + verification + "\nAFK Channel: **" + Context.Guild.GetVoiceChannel(serverConfig.AFKChannelID).Name + "**\nAFK Timeout: **" + serverConfig.AFKTimeout + "**\nAntispam Mute Time: **" + serverConfig.AntiSpamTime + "**\nAntispam Warn Ban: **" + serverConfig.AntiSpamWarn; string msg = "Server Name: **" + name + "**\nOwner: **" + owner + "**\nMember Count: **" + memberCount + "**\nDate Created: **" + date.ToString("MM/dd/yyyy hh:mm:ss") + "**" + configs + "**\n\n__Roles__\n**" + getAllRoles((SocketGuildUser)Context.User) + "**"; var result = from s in Context.Guild.VoiceChannels where s.Name.Contains("Member Count") select s; await PrintEmbedMessage("Server Stats", msg, iconUrl : Context.Guild.IconUrl); SocketVoiceChannel memberChan = result.FirstOrDefault(); await memberChan.ModifyAsync(m => { m.Name = "Member Count: " + Context.Guild.MemberCount; }); DataStorage.AddPairToStorage(memberChan.Guild.Name + " MemberChannel", memberChan.Id.ToString()); }
public async Task Verification(bool b) { ServerConfig config = ServerConfigs.GetConfig(Context.Guild); config.RequiresVerification = b; ServerConfigs.UpdateServerConfig(Context.Guild, config); await PrintEmbedMessage("Verification Set", string.Format("Verification set to {0}!", b), iconUrl : config.IconURL); }
public async Task VerifyRole(SocketRole role) { ServerConfig config = ServerConfigs.GetConfig(Context.Guild); config.VerificationRoleID = role.Id; ServerConfigs.UpdateServerConfig(Context.Guild, config); await PrintEmbedMessage("Verification Role Set", string.Format("Users will be added to the **{0}** role after verification!", role.Name), iconUrl : config.IconURL); }
public async Task SpamMuteTime(int mins) { ServerConfig config = ServerConfigs.GetConfig(Context.Guild); config.AntiSpamTime = mins; ServerConfigs.UpdateServerConfig(Context.Guild, config); await PrintEmbedMessage("Spam Mute Time Set", string.Format("Spam mute time set to {0}!", mins), iconUrl : config.IconURL); }
public async Task SpamWarnAmt(int amt) { ServerConfig config = ServerConfigs.GetConfig(Context.Guild); config.AntiSpamWarn = amt; ServerConfigs.UpdateServerConfig(Context.Guild, config); await PrintEmbedMessage("Spam Warn Set", string.Format("Spam warnings set to {0}!", amt), iconUrl : config.IconURL); }
public async Task AllowAds(bool b) { ServerConfig config = ServerConfigs.GetConfig(Context.Guild); config.AllowAdvertising = b; ServerConfigs.UpdateServerConfig(Context.Guild, config); await PrintEmbedMessage("Advertising Set", string.Format("Advertising set to {0}!", b), iconUrl : config.IconURL); }
public async Task DMEmbedMessage(string title = "", string msg = "", string url = "", string iconUrl = "", EmbedField[] fields = null, IUser author = null) { ServerConfig config = ServerConfigs.GetConfig(Context.Guild); EmbedBuilder embed = new EmbedBuilder(); embed.WithColor(config.EmbedColorRed, config.EmbedColorGreen, config.EmbedColorBlue); if (title != "") { embed.WithTitle(title); } if (config.FooterText != "") { embed.WithFooter(config.FooterText); } if (msg != "") { embed.WithDescription(msg); } if (author != null) { embed.WithAuthor(author); } if (url != "") { embed.WithUrl(url); } if (config.TimeStamp) { embed.WithCurrentTimestamp(); } if (iconUrl != "") { embed.WithThumbnailUrl(iconUrl); } if (fields != null) { for (int i = 0; i < fields.Length; i++) { embed.AddField(fields[i].name, fields[i].value, true); } } //Console.WriteLine(DateTime.Now + " | " + title + " |\n" + msg); string username = Context.User.Username + "#" + Context.User.Discriminator; string guildName = "Private Message"; if (!Context.IsPrivate) { guildName = Context.Guild.Name; } string text = DateTime.Now + " | " + username + " used " + title + " in " + guildName; Console.WriteLine(text); Log.AddTextToLog(text); var x = await Context.User.GetOrCreateDMChannelAsync(); await x.SendMessageAsync("", false, embed.Build()); }
public async Task Color(int red, int green, int blue) { ServerConfig config = ServerConfigs.GetConfig(Context.Guild); config.EmbedColorRed = red; config.EmbedColorGreen = green; config.EmbedColorBlue = blue; ServerConfigs.UpdateServerConfig(Context.Guild, config); await PrintEmbedMessage("Color Set", string.Format("**Red**: {0}\n**Green**: {1}\n**Blue**: {2}", red, green, blue), iconUrl : config.IconURL); }
public async Task AFKTimeout(int time) { time = time * 60; ServerConfig config = ServerConfigs.GetConfig(Context.Guild); config.AFKTimeout = time; await Context.Guild.ModifyAsync(m => { m.AfkTimeout = time; }); ServerConfigs.UpdateServerConfig(Context.Guild, config); await PrintEmbedMessage("AFK Timeout Set", string.Format("Users will be sent to {0} after **{1} minutes** of no activity!", config.AFKChannelName, config.AFKTimeout / 60), iconUrl : config.IconURL); }
public async Task FooterText([Remainder] string text) { ServerConfig config = ServerConfigs.GetConfig(Context.Guild); if (text == null || text == "") { await Context.Channel.SendMessageAsync(string.Format("Usage: {0}footer <text>\nExample: {0}footer Created By Abyscuit", config.Prefix)); } config.FooterText = text; ServerConfigs.UpdateServerConfig(Context.Guild, config); await PrintEmbedMessage("Footer Text Set", string.Format("New footer text set to:\n{0}", text), iconUrl : config.IconURL); }
private async Task Client_UserJoined(SocketGuildUser user) { await RepeatingTimer.UpdateAuditLog(user.Guild); ServerConfig config = ServerConfigs.GetConfig(user.Guild); string username = user.Username + "#" + user.Discriminator; if (config.NewUserMessage) { var channel = client.GetChannel(config.NewUserChannel) as SocketTextChannel; // Gets the channel to send the message in if (config.EnableServerStats) { await CreateStatChannels(user.Guild); await updMemberChan(user.Guild); } UserAccount account = UserAccounts.GetAccount(user); string msg = String.Format(Global.Welcome[rand.Next(Global.Welcome.Length)], username, user.Guild); //Welcome Message /* * var embed = new EmbedBuilder(); * embed.WithTitle("New User Joined!"); * embed.WithDescription(msg); * embed.WithThumbnailUrl(user.GetAvatarUrl()); * embed.WithColor(config.EmbedColorRed, config.EmbedColorGreen, config.EmbedColorBlue); * if (config.FooterText != "") * embed.WithFooter(config.FooterText); * if (config.TimeStamp) * embed.WithCurrentTimestamp(); * if (user.Id != BotID) * await channel.SendMessageAsync("", false, embed.Build()); //Welcomes the new user */ if (user.Id != BotID) { await channel.SendMessageAsync(msg); //Welcomes the new user } } Console.WriteLine(DateTime.Now.ToLocalTime() + " | " + username + " joined " + user.Guild.Name); if (config.RequiresVerification) { if (GetTChannel(user.Guild.TextChannels, "verification") == null) { await user.Guild.CreateTextChannelAsync("verification"); } await GetTChannel(user.Guild.TextChannels, "verification").SendMessageAsync("Type " + config.Prefix + "verify to verify your account."); } }
public async Task Prefix(string prefix) { if (prefix == " " || prefix == "") { await Context.Channel.SendMessageAsync("Usage: prefix <char>\nExample: @ByscuitBot prefix -"); return; } ServerConfig config = ServerConfigs.GetConfig(Context.Guild); config.Prefix = prefix; ServerConfigs.UpdateServerConfig(Context.Guild, config); await PrintEmbedMessage("Prefix Set", "Prefix has been set to " + prefix + ".\nYou can now use " + prefix + "help for the list of commands.", iconUrl : config.IconURL); }
public async Task Verify([Remainder] string captcha = null) { ServerConfig config = ServerConfigs.GetConfig(Context.Guild); SocketGuildUser user = (SocketGuildUser)Context.User; SocketRole role = Context.Guild.GetRole(config.VerificationRoleID); if (user.Roles.Contains(role)) { await Context.Channel.SendMessageAsync(Context.User.Mention + " is already verified!"); await Context.Message.DeleteAsync(); return; } await user.AddRoleAsync(role); await Context.Channel.SendMessageAsync(Context.User.Mention + " Verified!"); await Context.Message.DeleteAsync(); }
private async Task Client_UserLeft(SocketGuildUser user) { await RepeatingTimer.UpdateAuditLog(user.Guild); ServerConfig config = ServerConfigs.GetConfig(user.Guild); string username = user.Username + "#" + user.Discriminator; if (config.NewUserMessage) { var channel = client.GetChannel(config.NewUserChannel) as SocketTextChannel; // Gets the channel to send the message in if (config.EnableServerStats) { await CreateStatChannels(user.Guild); await updMemberChan(user.Guild); } string msg = String.Format(Global.Bye[rand.Next(Global.Bye.Length)], username, user.Guild) + " 👋"; //Bye message /* * var embed = new EmbedBuilder(); * embed.WithTitle($"{user.Username} Left"); * embed.WithThumbnailUrl(user.GetAvatarUrl()); * embed.WithDescription(msg); * embed.WithColor(config.EmbedColorRed, config.EmbedColorGreen, config.EmbedColorBlue); * if (config.FooterText != "") * embed.WithFooter(config.FooterText); * if (config.TimeStamp) * embed.WithCurrentTimestamp(); * if (user.Id != BotID) * await channel.SendMessageAsync("", false, embed.Build()); //Send byebye */ if (user.Id != BotID) { await channel.SendMessageAsync(msg); //Send byebye } } Console.WriteLine(DateTime.Now.ToLocalTime() + " | " + username + " left " + user.Guild.Name); }
private void applyConfigBtn_Click(object sender, EventArgs e) { SocketGuild guild = guilds[serversCBox.SelectedIndex]; config = ServerConfigs.GetConfig(guild); config.Prefix = prefixTxt.Text; if (afkChanCBox.SelectedIndex != -1) { SocketVoiceChannel vc = voiceChannels.ToArray()[afkChanCBox.SelectedIndex]; config.AFKChannelName = vc.Name; config.AFKChannelID = vc.Id; } config.RequiresVerification = veriToggle.Checked; if (veriToggle.Checked) { config.VerificationRoleID = roles.ToArray()[verRoleCBox.SelectedIndex].Id; } config.AFKTimeout = int.Parse(afkTimeCBox.SelectedItem.ToString()) * 60; config.EmbedColorRed = colorPrev.BackColor.R; config.EmbedColorGreen = colorPrev.BackColor.G; config.EmbedColorBlue = colorPrev.BackColor.B; config.TimeStamp = tsToggle.Checked; config.AllowAdvertising = adToggle.Checked; config.AntiSpamWarn = int.Parse(spamWarnTxt.Text); config.AntiSpamThreshold = int.Parse(spamThresholdTxt.Text); config.AntiSpamTime = double.Parse(spamTimeTxt.Text); config.FooterText = footerTxt.Text; config.NewUserMessage = newUsrMsgToggle.Checked; //SocketTextChannel tc = textChannels.ToArray()[afkChanCBox.SelectedIndex]; config.NewUserChannel = textChannels.ToArray()[newUsrChanCBox.SelectedIndex].Id; config.BlockMentionEveryone = eMentionTog.Checked; config.EnableServerStats = serverStatsTog.Checked; config.EnableLevelSystem = levelTog.Checked; ServerConfigs.SaveAccounts(); respLbl.Text = "Server Settings Updated!"; }
public async Task Test() { List <CommandInfo> cmds = CommandHandler.GetCommands(); string msg = "User Commands:\n"; string adminCmds = "Admin Commands:\n"; string ownerCmds = "Owner Commands:\n"; int x = 0; int y = 0; foreach (CommandInfo cmd in cmds) { if (cmd.Preconditions.Count > 0) { foreach (PreconditionAttribute precondition in cmd.Preconditions) { if (precondition is RequireBotPermissionAttribute) { RequireBotPermissionAttribute attribute = precondition as RequireBotPermissionAttribute; //msg += "*Requires Bot Permission: " + attribute.GuildPermission + "*\n"; } else if (precondition is RequireUserPermissionAttribute) { RequireUserPermissionAttribute attribute = precondition as RequireUserPermissionAttribute; //msg += "*Requires User Permission: " + attribute.GuildPermission + "*\n"; if (AdminAttribute(attribute)) { adminCmds += "**__" + cmd.Name + "__**\n"; if (!string.IsNullOrEmpty(cmd.Summary)) { adminCmds += "*" + cmd.Summary + "*\n"; } y++; } else { msg += "**__" + cmd.Name + "__**\n"; if (!string.IsNullOrEmpty(cmd.Summary)) { msg += "*" + cmd.Summary + "*\n"; } x++; } } else if (precondition is RequireOwnerAttribute) { RequireOwnerAttribute attribute = precondition as RequireOwnerAttribute; ownerCmds += "**__" + cmd.Name + "__**\n"; if (!string.IsNullOrEmpty(cmd.Summary)) { ownerCmds += "*" + cmd.Summary + "*\n"; } } } } else { msg += "**__" + cmd.Name + "__**\n"; if (!string.IsNullOrEmpty(cmd.Summary)) { msg += "*" + cmd.Summary + "*\n"; } x++; } if (y > 10) { adminCmds += "|"; y = 0; } if (x > 10) { msg += "|"; x = 0; } } string prefix = "/"; ServerConfig config = null; if (!Context.IsPrivate) { config = ServerConfigs.GetConfig(Context.Guild); } if (config != null) { prefix = config.Prefix; } foreach (string s in SplitMessage(msg, '|')) { if (!string.IsNullOrEmpty(s)) { await Context.Channel.SendMessageAsync(string.Format(s, prefix)); } } foreach (string s in SplitMessage(adminCmds, '|')) { if (!string.IsNullOrEmpty(s)) { await Context.Channel.SendMessageAsync(string.Format(s, prefix)); } } await Context.Channel.SendMessageAsync(ownerCmds); }
private void changeSettings() { textChannelCBox.Items.Clear(); afkChanCBox.Items.Clear(); verRoleCBox.Items.Clear(); roleCBox.Items.Clear(); newUsrChanCBox.Items.Clear(); usersCBox.Items.Clear(); usersList.Items.Clear(); SocketGuild guild = guilds[serversCBox.SelectedIndex]; textChannels = guild.TextChannels; voiceChannels = guild.VoiceChannels; roles = guild.Roles; users = guild.Users; foreach (SocketTextChannel chan in textChannels) { textChannelCBox.Items.Add(chan.Name); newUsrChanCBox.Items.Add(chan.Name); } foreach (SocketVoiceChannel chan in voiceChannels) { afkChanCBox.Items.Add(chan.Name); } foreach (SocketRole role in roles) { if (!role.IsEveryone) { verRoleCBox.Items.Add(role.Name); roleCBox.Items.Add(role.Name); } } foreach (SocketGuildUser user in users) { usersCBox.Items.Add(user.Username + "#" + user.Discriminator); usersList.Items.Add(user.Username + "#" + user.Discriminator); } if (roleCBox.Items.Count > 0) { roleCBox.SelectedIndex = 0; } if (usersList.Items.Count > 0) { usersList.SelectedIndex = 0; } ServerConfigs.LoadServerConfigs(); config = ServerConfigs.GetConfig(guild); tokenTxt.Text = Config.botconf.token; prefixTxt.Text = config.Prefix; string[] features = guild.Features.ToArray(); string featString = Environment.NewLine + "Features:"; foreach (string f in features) { featString += Environment.NewLine + f; } statsTxt.Text = string.Format("Total Users: {1}{0}Owner: {2}{0}Content Filter: {3}{0}Created On: {4}{0}Verification Level: {5}{0}Default Notifications: {6}", Environment.NewLine, guild.MemberCount, guild.Owner, guild.ExplicitContentFilter.ToString(), guild.CreatedAt, guild.VerificationLevel.ToString(), guild.DefaultMessageNotifications.ToString()); afkChanCBox.SelectedItem = config.AFKChannelName; veriToggle.Checked = config.RequiresVerification; if (veriToggle.Checked) { verRoleCBox.SelectedItem = guild.GetRole(config.VerificationRoleID).Name; } textChannelCBox.SelectedIndex = 0; afkTimeCBox.SelectedItem = "" + (config.AFKTimeout / 60); System.Drawing.Color color = System.Drawing.Color.FromArgb(config.EmbedColorRed, config.EmbedColorGreen, config.EmbedColorBlue); colorBtn.Text = string.Format("Color: {0},{1},{2}", color.R, color.G, color.B); colorPrev.BackColor = color; tsToggle.Checked = config.TimeStamp; adToggle.Checked = config.AllowAdvertising; spamWarnTxt.Text = "" + config.AntiSpamWarn; spamThresholdTxt.Text = "" + config.AntiSpamThreshold; spamTimeTxt.Text = "" + config.AntiSpamTime; footerTxt.Text = config.FooterText; newUsrMsgToggle.Checked = config.NewUserMessage; levelTog.Checked = config.EnableLevelSystem; serverStatsTog.Checked = config.EnableServerStats; if (newUsrMsgToggle.Checked) { newUsrChanCBox.SelectedItem = guild.GetTextChannel(config.NewUserChannel).Name; } eMentionTog.Checked = config.BlockMentionEveryone; //this.Refresh(); }
private static async void OnTimerTicked(object sender, ElapsedEventArgs e) { //----------GIVE AWAY----------- //if (Global.giveaway != giveAway) if (DateTime.Compare(timeToStop, DateTime.Now) < 0 && startTimer) { var embed = new EmbedBuilder(); embed.WithTitle("Timer Ended"); embed.WithDescription(""); embed.WithColor(100, 150, 255); embed.WithFooter("Created by Abyscuit"); await channel.SendMessageAsync("", false, embed.Build()); startTimer = !startTimer; //Global.giveaway = giveAway; } foreach (Giveaway giveaway in GiveawayManager.Giveaways) { if (giveaway.EndTime.CompareTo(DateTime.Now) < 0) { SocketTextChannel textChannel = channel.Guild.GetTextChannel(giveaway.ChannelID); RestUserMessage message = (RestUserMessage)await textChannel.GetMessageAsync(giveaway.MessageID); ServerConfig config = ServerConfigs.GetConfig(channel.Guild); if (giveaway.UsersID.Count > 0) { int win = Global.rand.Next(0, giveaway.UsersID.Count - 1); ulong winner = giveaway.UsersID[win]; giveaway.WinnerID = winner; SocketUser user = channel.Guild.GetUser(winner); EmbedBuilder embed = new EmbedBuilder(); embed.WithTitle(giveaway.Item); embed.WithDescription("**Giveaway Ended " + giveaway.EndTime.ToShortDateString() + " " + giveaway.EndTime.ToShortTimeString() + "!**\nWinner is " + user.Mention + ""); embed.WithFooter(config.FooterText); embed.WithColor(config.EmbedColorRed, config.EmbedColorGreen, config.EmbedColorBlue); if (config.TimeStamp) { embed.WithCurrentTimestamp(); } await message.ModifyAsync(m => { m.Embed = embed.Build(); }); embed.WithTitle(giveaway.Item); embed.WithDescription("**Winner is " + user.Mention + "**"); embed.WithFooter(config.FooterText); embed.WithColor(config.EmbedColorRed, config.EmbedColorGreen, config.EmbedColorBlue); if (config.TimeStamp) { embed.WithCurrentTimestamp(); } await textChannel.SendMessageAsync("🎉**GIVEAWAY ENDED**🎉", false, embed.Build()); } else { EmbedBuilder embed = new EmbedBuilder(); SocketUser user = channel.Guild.GetUser(giveaway.CreatorID); embed.WithTitle(giveaway.Item); embed.WithDescription("**Giveaway Ended " + giveaway.EndTime.ToShortDateString() + " " + giveaway.EndTime.ToShortTimeString() + "!**\nNo one entered!\n" + user.Mention + " may start a new one."); embed.WithFooter(config.FooterText); embed.WithColor(config.EmbedColorRed, config.EmbedColorGreen, config.EmbedColorBlue); if (config.TimeStamp) { embed.WithCurrentTimestamp(); } await message.ModifyAsync(m => { m.Embed = embed.Build(); }); embed.WithTitle(giveaway.Item); embed.WithDescription("**No one entered!**\nYou may start another giveaway " + user.Mention); embed.WithFooter(config.FooterText); embed.WithColor(config.EmbedColorRed, config.EmbedColorGreen, config.EmbedColorBlue); if (config.TimeStamp) { embed.WithCurrentTimestamp(); } await textChannel.SendMessageAsync("🎉**GIVEAWAY ENDED**🎉", false, embed.Build()); } GiveawayManager.DeleteGiveaway(message); GiveawayManager.Save(); } } //-------Spam account timer---------- foreach (Antispam.SpamAccount spamAccount in Antispam.spamAccounts) { User_Accounts.UserAccount account = User_Accounts.UserAccounts.GetAccount(spamAccount.DiscordID); if (account.IsMuted) { if (DateTime.Compare(spamAccount.BanTime, DateTime.Now) < 0) { account.IsMuted = false; User_Accounts.UserAccounts.SaveAccounts(); } } } //-------Form Updates------------- if (clrMsgTime.CompareTo(DateTime.Now) < 0 && clrMsg) { await channel.DeleteMessageAsync(Global.MessageIdToTrack); clrMsg = false; } int newCount = Program.client.Guilds.Count; if (oldGCount != newCount) { Program.form.updateServers(); for (int i = oldGCount; i < newCount; i++) { serverDay.Add(DateTime.Now); dayCheck.Add(false); } oldGCount = newCount; } //---------Timer for events-------- /* * SocketGuild[] guilds = Program.client.Guilds.ToArray(); * * for (int i = 0; i < guilds.Length; i++) * { * bool genFound = false; * foreach (SocketTextChannel textChannel in guilds[i].TextChannels) * { * if (textChannel.Name.ToLower().Contains("general")) * { * generalChannel = textChannel; * genFound = true; * break; * } * } * if (!genFound) * generalChannel = guilds[i].DefaultChannel; * if (!dayCheck[i]) * { * //birthday check * DateTimeOffset serverCreated = guilds[i].CreatedAt; * DateTime serverBirthday = new DateTime(DateTime.Now.Year, serverCreated.Month, serverCreated.Day); * if (compareDates(serverBirthday, DateTime.Now)) * { * await generalChannel.SendMessageAsync(String.Format(Global.Holidays[0], guilds[i].Name, * DateTimeOffset.Now.Subtract(guilds[i].CreatedAt).TotalDays / 365)); * } * * //4th july check * DateTime _4thJuly = new DateTime(DateTime.Now.Year, 7, 4); * if (compareDates(_4thJuly, DateTime.Now)) * { * //await generalChannel.SendMessageAsync(Global.Holidays[1]); * } * //halloween check * DateTime HALLOWEEN_CHECK = new DateTime(DateTime.Now.Year, 10, 31); * if (compareDates(HALLOWEEN_CHECK, DateTime.Now)) * { * await generalChannel.SendMessageAsync(Global.Holidays[2]); * } * * } * if (!compareDates(DateTime.Now, serverDay[i])) * { * dayCheck[i] = true; * serverDay[i] = DateTime.Now; * Console.WriteLine(DateTime.Now + " | Events checked for " + guilds[i].Name); * } * } */ }
private async Task Client_MessageReceived(SocketMessage s) { var msg = s as SocketUserMessage; if (msg == null) { return; } var context = new SocketCommandContext(client, msg); ulong guildID = 0; SocketTextChannel generalchan = null; ServerConfig config = new ServerConfig(); UserAccount userAccount = null; Antispam.SpamAccount spamAccount = null; //Load Accounts UserAccounts.LoadUserAccts(); SteamAccounts.LoadUserAccts(); ServerConfigs.LoadServerConfigs(); NanoPool.LoadAccounts(); MemeLoader.LoadMemes(); Antispam.LoadSpamAccount(); GiveawayManager.LoadGiveaways(); //----------Do Tests-------- //if (!context.IsPrivate) await RepeatingTimer.UpdateAuditLog(context.Guild);] //Mute Check userAccount = UserAccounts.GetAccount(context.User); spamAccount = Antispam.GetAccount(context.User); if (oldMessage.Count > 0) { if (oldMessage[oldMessage.Count - 1].Content == s.Content) { for (int i = 0; i < oldMessage.Count; i++) { if (oldMessage[i].Content == s.Content && oldMessage[i].Embeds.Count == 0) { msgCount++; if (msgCount >= 5) { try { await s.DeleteAsync(); } catch (Exception ex) { string exMsg = DateTime.Now + " | EXCEPTION: " + ex.Message; Console.WriteLine(exMsg); Log.LogException(exMsg); } string mes = DateTime.Now + " | " + context.User + " suspected raid account. Ban request...."; Console.WriteLine(mes); } } } } } if (oldMessage.Count >= 20) { oldMessage.RemoveAt(0); } oldMessage.Add(s); if (!context.IsPrivate) { config = ServerConfigs.GetConfig(context.Guild); RepeatingTimer.channel = (SocketTextChannel)context.Channel; if (!updated.Contains(context.Guild)) { ServerConfigs.UpdateServerConfig(context.Guild, config); updated.Add(context.Guild); } if (config.RequiresVerification) { if (GetTChannel(context.Guild.TextChannels, "verification") == null) { await context.Guild.CreateTextChannelAsync("verification"); } } if (userAccount.IsMuted) { await context.Message.DeleteAsync(); return; } //Get Guild ID guildID = context.Guild.Id; DataStorage.AddPairToStorage(context.Guild.Name + "ID", guildID.ToString()); generalchan = GetTChannel(context.Guild.TextChannels, "general"); } //Bot Check if (!context.User.IsBot) { if (!context.IsPrivate) { if (!config.AllowAdvertising) { if (context.Message.Content.Contains(context.Guild.EveryoneRole.ToString()) && context.Message.Content.Contains("https://discord.gg/")) { await context.Message.DeleteAsync(); await context.Channel.SendMessageAsync(context.User.Mention + " Advertising discord servers is not allowed here."); return; } } if (config.BlockMentionEveryone) { if (context.Message.Content.Contains(context.Guild.EveryoneRole.ToString())) { await context.Message.DeleteAsync(); await context.Channel.SendMessageAsync(context.User.Mention + " mentioning everyone is prohibited!"); return; } } //Check for raid from multiple account spam //Add when you wake up... spamAccount.LastMessages.Add(DateTime.Now); if (spamAccount.BanAmount > 0) { if (Math.Abs(spamAccount.LastBan.Subtract(DateTime.Now).Days) > 10) //Reset ban amount after 10 days { spamAccount.BanAmount = 0; } } if (spamAccount.LastMessages.Count > 3) { //Get last 4 messages sent DateTime d1 = spamAccount.LastMessages[0]; DateTime d2 = spamAccount.LastMessages[1]; DateTime d3 = spamAccount.LastMessages[2]; DateTime d4 = spamAccount.LastMessages[3]; TimeSpan t1 = new TimeSpan(); TimeSpan t2 = new TimeSpan(); TimeSpan t3 = new TimeSpan(); //Subtract them from each other by Milliseconds t1 = d1.Subtract(d2); t2 = d2.Subtract(d3); t3 = d3.Subtract(d4); double mil1 = Math.Abs(t1.TotalMilliseconds); double mil2 = Math.Abs(t2.TotalMilliseconds); double mil3 = Math.Abs(t3.TotalMilliseconds); //Console.WriteLine(mil1 + "\n" + mil2 + "\n" + mil3); //If all past 4 messages are within spam threshold then its considerd spam if (mil1 <= Antispam.millisecondThreshold && //Threshold is 5 seconds mil2 <= Antispam.millisecondThreshold && mil3 <= Antispam.millisecondThreshold) { spamAccount.BanAmount++; string message = ""; DateTime banTime = DateTime.Now; if (spamAccount.BanAmount < config.AntiSpamWarn) { message = "\nPlease stop spamming you have been muted for 30 seconds!"; banTime = DateTime.Now.AddSeconds(30); } if (spamAccount.BanAmount >= config.AntiSpamWarn && spamAccount.BanAmount < config.AntiSpamThreshold) { int time = (int)config.AntiSpamTime; message = "\nYou have been muted for " + time + " Minutes! " + context.Guild.Owner.Mention; banTime = DateTime.Now.AddMinutes(time); } if (spamAccount.BanAmount > config.AntiSpamThreshold) { SocketGuildUser user = (SocketGuildUser)context.User; await user.BanAsync(1, "Spamming"); await context.Channel.SendMessageAsync(context.User.Username + " was banned for 1 day for spamming!"); return; } spamAccount.BanTime = banTime; spamAccount.LastBan = DateTime.Now; await context.Channel.SendMessageAsync(context.User.Mention + message); spamAccount.LastMessages.Clear(); Antispam.UpdateAccount(context.User, spamAccount); Antispam.SaveAccounts(); userAccount.IsMuted = true; UserAccounts.SaveAccounts(); return; } spamAccount.LastMessages.Clear(); } Antispam.SaveAccounts(); if (config.EnableServerStats) { //If stat channels dont exist await CreateStatChannels(context.Guild); await updMemberChan(context.Guild); //Update Stat channels } if (config.EnableLevelSystem) { uint oldlvl = userAccount.LevelNumber; userAccount.XP += 10; //Xp gain userAccount.Points += 10; //Pointshop if (oldlvl != userAccount.LevelNumber) { for (int i = 0; i < LevelingSytem.levelUp.Length; i++) { if (userAccount.LevelNumber == LevelingSytem.levelUp[i]) { IGuildUser user = (IGuildUser)context.User; IRole[] r = user.Guild.Roles.ToArray(); IRole addrole = null; for (int i2 = 0; i2 < r.Length; i2++) { if (r[i2].Name.ToLower() == LevelingSytem.upgradeRoles[i].ToLower()) { addrole = r[i2]; break; } } if (addrole != null) { ulong?roleID = null; foreach (ulong r2 in user.RoleIds) { if (r2 == addrole.Id) { roleID = r2; break; } }//end foreach loop if (roleID == null) { await user.AddRoleAsync(addrole); await context.Channel.SendMessageAsync("__" + user.Username + "__ earned role **" + addrole + "**!", false); } //end if roleID } //end if addrole != null } // end if level up } //end levels loop string message = "Congrats " + context.User.Mention + ", You just advanced to **Level " + userAccount.LevelNumber + "!**"; await context.Channel.SendMessageAsync(message); } //end level check } //end level system check } //end if EnableLevelSystem UserAccounts.SaveAccounts(); } //end isPrivate check int argPos = 0; if (msg.HasStringPrefix("" + config.Prefix, ref argPos) || msg.HasMentionPrefix(client.CurrentUser, ref argPos)) { if (context.IsPrivate) { config = new ServerConfig(); } else { config = ServerConfigs.GetConfig(context.Guild); } IResult result = null; result = await service.ExecuteAsync(context, argPos, null); if (!result.IsSuccess && result.Error != CommandError.UnknownCommand) { bool errorCheck = true; if (context.Message.Content.Contains("creatememe") && context.Message.Attachments.Count > 0) { if (result.ErrorReason.Contains("User not found")) { errorCheck = false; } } if (errorCheck) { string message = "Error when running this command\n**" + result.ErrorReason + "**\n\nView console for more info"; var embed = new EmbedBuilder(); embed.WithTitle("Command Error"); embed.WithDescription(message); embed.WithColor(config.EmbedColorRed, config.EmbedColorGreen, config.EmbedColorBlue); if (config.FooterText != "") { embed.WithFooter(config.FooterText); } if (config.TimeStamp) { embed.WithCurrentTimestamp(); } await context.Channel.SendMessageAsync("", false, embed.Build()); Console.WriteLine(result.ErrorReason); Console.WriteLine(result.Error); } } } GetAllVoiceChannels(context.Guild.VoiceChannels); GetAllTextChannels(context.Guild.TextChannels); }