Sanitized everything i could think of so far which which could cause accidental @everyone or @here mentions
This commit is contained in:
parent
0c9fa4b453
commit
a9235dad93
@ -1,6 +1,7 @@
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Attributes;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using NLog;
|
||||
@ -42,12 +43,12 @@ namespace NadekoBot.Modules.Administration
|
||||
if (channel == null) //maybe warn the server owner that the channel is missing
|
||||
return;
|
||||
|
||||
var msg = conf.ChannelByeMessageText.Replace("%user%", "**" + user.Username + "**");
|
||||
var msg = conf.ChannelByeMessageText.Replace("%user%", user.Username).Replace("%server%", user.Guild.Name);
|
||||
if (string.IsNullOrWhiteSpace(msg))
|
||||
return;
|
||||
try
|
||||
{
|
||||
var toDelete = await channel.SendMessageAsync(msg).ConfigureAwait(false);
|
||||
var toDelete = await channel.SendMessageAsync(msg.SanitizeMentions()).ConfigureAwait(false);
|
||||
if (conf.AutoDeleteByeMessages)
|
||||
{
|
||||
var t = Task.Run(async () =>
|
||||
@ -82,7 +83,7 @@ namespace NadekoBot.Modules.Administration
|
||||
{
|
||||
try
|
||||
{
|
||||
var toDelete = await channel.SendMessageAsync(msg).ConfigureAwait(false);
|
||||
var toDelete = await channel.SendMessageAsync(msg.SanitizeMentions()).ConfigureAwait(false);
|
||||
if (conf.AutoDeleteGreetMessages)
|
||||
{
|
||||
var t = Task.Run(async () =>
|
||||
@ -172,7 +173,7 @@ namespace NadekoBot.Modules.Administration
|
||||
conf = uow.GuildConfigs.For(channel.Guild.Id);
|
||||
if (!string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
conf.ChannelGreetMessageText = text;
|
||||
conf.ChannelGreetMessageText = text.SanitizeMentions();
|
||||
uow.GuildConfigs.Update(conf);
|
||||
await uow.CompleteAsync();
|
||||
}
|
||||
@ -180,7 +181,7 @@ namespace NadekoBot.Modules.Administration
|
||||
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
await channel.SendMessageAsync("`Current greet message:` " + conf.ChannelGreetMessageText);
|
||||
await channel.SendMessageAsync("`Current greet message:` " + conf.ChannelGreetMessageText.SanitizeMentions());
|
||||
return;
|
||||
}
|
||||
await channel.SendMessageAsync("New greet message set.").ConfigureAwait(false);
|
||||
@ -275,7 +276,7 @@ namespace NadekoBot.Modules.Administration
|
||||
conf = uow.GuildConfigs.For(channel.Guild.Id);
|
||||
if (!string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
conf.ChannelByeMessageText = text;
|
||||
conf.ChannelByeMessageText = text.SanitizeMentions();
|
||||
uow.GuildConfigs.Update(conf);
|
||||
await uow.CompleteAsync();
|
||||
}
|
||||
@ -283,7 +284,7 @@ namespace NadekoBot.Modules.Administration
|
||||
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
await channel.SendMessageAsync("`Current bye message:` " + conf.ChannelGreetMessageText);
|
||||
await channel.SendMessageAsync("`Current bye message:` " + conf.ChannelGreetMessageText.SanitizeMentions());
|
||||
return;
|
||||
}
|
||||
await channel.SendMessageAsync("New bye message set.").ConfigureAwait(false);
|
||||
|
@ -56,6 +56,8 @@ namespace NadekoBot.Modules.Games
|
||||
IsActive = true;
|
||||
CurrentSentence = GetRandomSentence();
|
||||
var i = (int)(CurrentSentence.Length / WORD_VALUE * 1.7f);
|
||||
try
|
||||
{
|
||||
await channel.SendMessageAsync($@":clock2: Next contest will last for {i} seconds. Type the bolded text as fast as you can.").ConfigureAwait(false);
|
||||
|
||||
|
||||
@ -70,7 +72,7 @@ namespace NadekoBot.Modules.Games
|
||||
}
|
||||
catch (Exception ex) { _log.Warn(ex); }
|
||||
|
||||
await msg.ModifyAsync(m => m.Content = $":book:**{CurrentSentence.Replace(" ", " \x200B")}**:book:").ConfigureAwait(false);
|
||||
await msg.ModifyAsync(m => m.Content = $"**{Format.Sanitize(CurrentSentence.Replace(" ", " \x200B")).SanitizeMentions()}**:book:").ConfigureAwait(false);
|
||||
sw.Start();
|
||||
HandleAnswers();
|
||||
|
||||
@ -82,14 +84,19 @@ namespace NadekoBot.Modules.Games
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
catch { }
|
||||
finally
|
||||
{
|
||||
await Stop().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
public string GetRandomSentence()
|
||||
{
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
return uow.TypingArticles.GetRandom()?.Text ?? "No typing articles found. Use `>typeadd` command to add a new article for typing.";
|
||||
return uow.TypingArticles.GetRandom()?.Text ?? $"No typing articles found. Use `{NadekoBot.ModulePrefixes[typeof(Games).Name]}typeadd` command to add a new article for typing.";
|
||||
}
|
||||
|
||||
}
|
||||
@ -194,7 +201,7 @@ namespace NadekoBot.Modules.Games
|
||||
uow.TypingArticles.Add(new Services.Database.Models.TypingArticle
|
||||
{
|
||||
Author = imsg.Author.Username,
|
||||
Text = text
|
||||
Text = text.SanitizeMentions(),
|
||||
});
|
||||
await uow.CompleteAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -34,7 +35,7 @@ namespace NadekoBot.Modules.Games.Trivia
|
||||
|
||||
foreach (var item in arr)
|
||||
{
|
||||
var tq = new TriviaQuestion(item["Question"].ToString(), item["Answer"].ToString(), item["Category"]?.ToString());
|
||||
var tq = new TriviaQuestion(item["Question"].ToString().SanitizeMentions(), item["Answer"].ToString().SanitizeMentions(), item["Category"]?.ToString());
|
||||
pool.Add(tq);
|
||||
}
|
||||
var r = new NadekoRandom();
|
||||
|
@ -77,7 +77,7 @@ namespace NadekoBot.Modules.Utility
|
||||
toReturn += $@"`Id:` **{user.Id}**
|
||||
`Current Game:` **{(user.Game?.Name == null ? "-" : user.Game.Name)}**
|
||||
`Joined At:` **{user.JoinedAt}**
|
||||
`Roles:` **({user.Roles.Count()}) - {string.Join(", ", user.Roles.Select(r => r.Name))}**
|
||||
`Roles:` **({user.Roles.Count()}) - {string.Join(", ", user.Roles.Select(r => r.Name)).SanitizeMentions()}**
|
||||
`AvatarUrl:` **{user.AvatarUrl}**";
|
||||
await msg.Reply(toReturn).ConfigureAwait(false);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using NadekoBot.Attributes;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Database;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
@ -34,7 +35,7 @@ namespace NadekoBot.Modules.Utility
|
||||
if (quote == null)
|
||||
return;
|
||||
|
||||
await channel.SendMessageAsync("📣 " + quote.Text);
|
||||
await channel.SendMessageAsync("📣 " + quote.Text.SanitizeMentions());
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
|
@ -2,6 +2,7 @@
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Attributes;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using NadekoBot.Services.Database;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
@ -47,7 +48,7 @@ namespace NadekoBot.Modules.Utility
|
||||
|
||||
foreach (var r in reminders)
|
||||
{
|
||||
var t = StartReminder(r);
|
||||
try { var t = StartReminder(r); } catch (Exception ex) { _log.Warn(ex); }
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,6 +79,7 @@ namespace NadekoBot.Modules.Utility
|
||||
await ch.SendMessageAsync(
|
||||
replacements.Aggregate(RemindMessageFormat,
|
||||
(cur, replace) => cur.Replace(replace.Key, replace.Value(r)))
|
||||
.SanitizeMentions()
|
||||
).ConfigureAwait(false); //it works trust me
|
||||
}
|
||||
catch (Exception ex) { _log.Warn(ex); }
|
||||
@ -179,7 +181,7 @@ namespace NadekoBot.Modules.Utility
|
||||
await uow.CompleteAsync();
|
||||
}
|
||||
|
||||
try { await channel.SendMessageAsync($"⏰ I will remind \"{(ch is ITextChannel ? ((ITextChannel)ch).Name : umsg.Author.Username)}\" to \"{message.ToString()}\" in {output}. ({time:d.M.yyyy.} at {time:HH:mm})").ConfigureAwait(false); } catch { }
|
||||
try { await channel.SendMessageAsync($"⏰ I will remind \"{(ch is ITextChannel ? ((ITextChannel)ch).Name : umsg.Author.Username)}\" to \"{message.SanitizeMentions()}\" in {output}. ({time:d.M.yyyy.} at {time:HH:mm})").ConfigureAwait(false); } catch { }
|
||||
await StartReminder(rem);
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ namespace NadekoBot.Modules.Utility
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task InRole(IUserMessage umsg, [Remainder] string roles = null)
|
||||
public async Task InRole(IUserMessage umsg, [Remainder] string roles)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(roles))
|
||||
return;
|
||||
@ -122,11 +122,11 @@ namespace NadekoBot.Modules.Utility
|
||||
var guild = channel.Guild;
|
||||
if (target != null)
|
||||
{
|
||||
await msg.Reply($"`List of roles for **{target.Username}**:` \n• " + string.Join("\n• ", target.Roles.Except(new[] { guild.EveryoneRole }).OrderBy(r => r.Position)));
|
||||
await msg.Reply($"`List of roles for **{target.Username}**:` \n• " + string.Join("\n• ", target.Roles.Except(new[] { guild.EveryoneRole }).OrderBy(r => r.Position)).SanitizeMentions());
|
||||
}
|
||||
else
|
||||
{
|
||||
await msg.Reply("`List of roles:` \n• " + string.Join("\n• ", guild.Roles.Except(new[] { guild.EveryoneRole }).OrderBy(r=>r.Position)));
|
||||
await msg.Reply("`List of roles:` \n• " + string.Join("\n• ", guild.Roles.Except(new[] { guild.EveryoneRole }).OrderBy(r=>r.Position)).SanitizeMentions());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,9 @@ namespace NadekoBot.Extensions
|
||||
http.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
|
||||
}
|
||||
|
||||
public static string SanitizeMentions(this string str) =>
|
||||
str.Replace("@everyone", "@everyοne").Replace("@here", "@һere");
|
||||
|
||||
public static double UnixTimestamp(this DateTime dt) => dt.ToUniversalTime().Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
|
||||
|
||||
public static async Task<IUserMessage> SendMessageAsync(this IGuildUser user, string message, bool isTTS = false) =>
|
||||
|
Loading…
Reference in New Issue
Block a user