Skip to content

Commit

Permalink
Some future stuff sketches
Browse files Browse the repository at this point in the history
  • Loading branch information
panthernet committed Mar 6, 2019
1 parent 0ae6adf commit 92002ac
Show file tree
Hide file tree
Showing 16 changed files with 812 additions and 18 deletions.
6 changes: 6 additions & 0 deletions ThunderED/API/DiscordAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -768,5 +768,11 @@ public List<string> GetUserRoleNames(ulong id)
{
return GetUser(id).Roles.Select(a => a.Name).ToList();
}

public List<SocketGuildUser> GetUsers(ulong channelId, bool onlineOnly)
{
var users = channelId == 0 ? GetGuild().Users.ToList() : GetGuild().GetChannel(channelId).Users.ToList();
return onlineOnly ? users.Where(a => a.Status != UserStatus.Offline).ToList() : users;
}
}
}
51 changes: 51 additions & 0 deletions ThunderED/Classes/DiscordCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,45 @@ public async Task Stats2()
}
}

[Command("caps", RunMode = RunMode.Async), Summary("")]
public async Task Caps()
{
var forbidden = APIHelper.DiscordAPI.GetConfigForbiddenPublicChannels();
if(forbidden.Any() && forbidden.Contains(Context.Channel.Id))
return;
if (!SettingsManager.Settings.CommandsConfig.EnableCapsCommand)
return;
if(SettingsManager.Settings.CommandsConfig.CapsCommandDiscordChannels.Any() && !SettingsManager.Settings.CommandsConfig.CapsCommandDiscordChannels.Contains(Context.Channel.Id))
return;
if (SettingsManager.Settings.CommandsConfig.CapsCommandDiscordRoles.Any() && !await IsAllowedByRoles(SettingsManager.Settings.CommandsConfig.CapsCommandDiscordRoles, Context.User.Id))
return;

await APIHelper.DiscordAPI.ReplyMessageAsync(Context, LM.Get("helpCaps", SettingsManager.Settings.Config.BotDiscordCommandPrefix, "caps"));
}

[Command("caps", RunMode = RunMode.Async), Summary("")]
public async Task Caps([Remainder] string x)
{
var forbidden = APIHelper.DiscordAPI.GetConfigForbiddenPublicChannels();
if(forbidden.Any() && forbidden.Contains(Context.Channel.Id))
return;
if (!SettingsManager.Settings.CommandsConfig.EnableCapsCommand)
return;
if(SettingsManager.Settings.CommandsConfig.CapsCommandDiscordChannels.Any() && !SettingsManager.Settings.CommandsConfig.CapsCommandDiscordChannels.Contains(Context.Channel.Id))
return;
if (SettingsManager.Settings.CommandsConfig.CapsCommandDiscordRoles.Any() && !await IsAllowedByRoles(SettingsManager.Settings.CommandsConfig.CapsCommandDiscordRoles, Context.User.Id))
return;

try
{
await TickManager.GetModule<CapsModule>().ProcessWhoCommand(Context, x);
}
catch (Exception ex)
{
await LogHelper.LogEx("caps", ex);
}
}

/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -1253,6 +1292,18 @@ private async Task<bool> IsExecByAdmin()
return true;
}

private async Task<bool> IsAllowedByRoles(List<string> roles, ulong userId)
{
var result = APIHelper.DiscordAPI.GetUserRoleNames(userId);
if (!result.Any(roles.Contains))
{
await APIHelper.DiscordAPI.ReplyMessageAsync(Context, LM.Get("comRequireRole"), true);
return false;
}

return true;
}

#endregion
}
}
20 changes: 20 additions & 0 deletions ThunderED/Classes/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace TED_ConfigEditor.Classes
#else
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
Expand All @@ -22,6 +23,10 @@ public class ThunderSettings: SettingsBase<ThunderSettings>
{
[ConfigEntryName("")]
public ConfigSettings Config { get; set; } = new ConfigSettings();
[ConfigEntryName("")]
[StaticConfigEntry]
public CommandsConfigSettings CommandsConfig { get; set; } = new CommandsConfigSettings();

[ConfigEntryName("moduleWebServer")]
public WebServerModuleSettings WebServerModule { get; set; } = new WebServerModuleSettings();
[ConfigEntryName("moduleAuthWeb")]
Expand Down Expand Up @@ -104,6 +109,20 @@ public string Validate(List<string> usedModules)
#endif
}

public class CommandsConfigSettings
{
#if EDITOR
public ObservableCollection<string> CapsCommandDiscordRoles { get; set; } = new ObservableCollection<string>();
public ObservableCollection<ulong> CapsCommandDiscordChannels { get; set; } = new ObservableCollection<ulong>();
#else
public List<string> CapsCommandDiscordRoles { get; set; } = new List<string>();
public List<ulong> CapsCommandDiscordChannels { get; set; } = new List<ulong>();
#endif

[Comment("Enable !caps command")]
public bool EnableCapsCommand { get; set; } = false;
}

public class SovTrackerModuleSettings: ValidatableSettings
{
[Required]
Expand Down Expand Up @@ -1454,6 +1473,7 @@ public class ConfigSettings: ValidatableSettings
[Comment("Optional path to language files folder. Empty by default and will use default folder")]
public string LanguageFilesFolder { get; set; }


#if EDITOR
public override string this[string columnName]
{
Expand Down
2 changes: 2 additions & 0 deletions ThunderED/Classes/SettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static partial class SettingsManager
public static ThunderSettings Settings { get; private set; }

public static bool IsLinux { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
public static string FileShipsData { get; set; }


public static string Prepare(string settingsPath = null)
Expand All @@ -65,6 +66,7 @@ public static string Prepare(string settingsPath = null)
FileTemplateHRM_MailBody = Path.Combine(RootDirectory, "Templates", "hrm_inspect_mail.html");
FileTemplateHRM_Table = Path.Combine(RootDirectory, "Templates", "hrm_inspect_table.html");
FileTemplateHRM_SearchMailPage = Path.Combine(RootDirectory, "Templates", "hrmMailSearch.html");
FileShipsData = Path.Combine(DataDirectory, "shipdata.json");
return null;
}
catch (Exception ex)
Expand Down
5 changes: 4 additions & 1 deletion ThunderED/Classes/TickManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static void LoadModules()
if (SettingsManager.Settings.Config.ModuleHRM)
Modules.Add(new HRMModule());

//on demand modules - only could be pinged by other modules
//on demand modules - only could be pinged by other modules or commands
if (SettingsManager.Settings.Config.ModuleLiveKillFeed)
OnDemandModules.Add(new LiveKillFeedModule());

Expand All @@ -96,6 +96,9 @@ public static void LoadModules()
if (SettingsManager.Settings.Config.ModuleChatRelay)
OnDemandModules.Add(new ChatRelayModule());

if (SettingsManager.Settings.CommandsConfig.EnableCapsCommand)
OnDemandModules.Add(new CapsModule());



//IMPORTANT - web auth is the last module - to be the last for 404 handling
Expand Down
3 changes: 2 additions & 1 deletion ThunderED/Helpers/LogCat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public enum LogCat
ContractNotif,
AuthStandings,
SovTracker,
SimplAuth
SimplAuth,
Caps
}
}
10 changes: 9 additions & 1 deletion ThunderED/Languages/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -478,5 +478,13 @@
"dailyRatingTopKill": "Top Killers",
"dailyRatingTopIsk": "Top ISK Sinkers",
"dailyRatingTopPts": "Top Pts Hunters",
"dailyRatingTopEff": "Top Efficiency"
"dailyRatingTopEff": "Top Efficiency",
"capsNoUsersFound": "No eligible users found!",
"helpCaps": "Caps command displays information about capital ship drivers on channel/server. Examples: {0}{1} who , {0}{1} who online, {0}{1} all",
"capsCommandRunning": "Command is already running, try again later",
"of": "of",
"capsCalibr5": "Max Calibration",
"comRequireRole": "You must have special Discord role to run this command",
"errFileNotFound": "File {0} not found!",
"errFileContainsInvalidData": "File {0} contains invalid data!"
}
12 changes: 10 additions & 2 deletions ThunderED/Languages/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -472,5 +472,13 @@
"dailyRatingTopKill": "Топ Убийцы",
"dailyRatingTopIsk": "Топ ISK",
"dailyRatingTopPts": "Топ Охотники",
"dailyRatingTopEff": "Топ Эффективность"
}
"dailyRatingTopEff": "Топ Эффективность",
"capsNoUsersFound": "Доступных мемберов не найдено!",
"helpCaps": "Команда caps отображает данные о капиталоводах в канале/на сервере. Примеры: {0}{1} who , {0}{1} who online, {0}{1} all",
"capsCommandRunning": "Команда уже выполняется, попробуйте позже",
"of": "из",
"capsCalibr5": "Макс. Калибровка",
"comRequireRole": "У вас должна быть особая роль Discord, чтобы выполнить эту команду",
"errFileNotFound": "Файл {0} не найден!",
"errFileContainsInvalidData": "Файл {0} содержит неверные данные!"
}
10 changes: 6 additions & 4 deletions ThunderED/Modules/MailModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,11 @@ public override async Task Run(object prm)

private static async Task SendMailNotification(ulong channel, JsonClasses.Mail mail, string from, string mention)
{
var stamp = DateTime.Parse(mail.timestamp).ToString(SettingsManager.Settings.Config.ShortTimeFormat);
// var stamp = DateTime.Parse(mail.timestamp).ToString(SettingsManager.Settings.Config.ShortTimeFormat);
var body = await PrepareBodyMessage(mail.body);
var fields = body.Split(1023);

var embed = new EmbedBuilder()
/* var embed = new EmbedBuilder()
.WithThumbnailUrl(SettingsManager.Settings.Resources.ImgMail);
var cnt = 0;
foreach (var field in fields)
Expand All @@ -241,9 +241,11 @@ private static async Task SendMailNotification(ulong channel, JsonClasses.Mail m
embed.AddField($"-", string.IsNullOrWhiteSpace(field) ? "---" : field);
cnt++;
}
embed.WithFooter($"{LM.Get("mailDate")} {stamp}");
embed.WithFooter($"{LM.Get("mailDate")} {stamp}");*/
var ch = APIHelper.DiscordAPI.GetChannel(channel);
await APIHelper.DiscordAPI.SendMessageAsync(ch, $"{mention} {from}", embed.Build()).ConfigureAwait(false);
await APIHelper.DiscordAPI.SendMessageAsync(ch, $"{mention} {from}");
foreach (var field in fields)
await APIHelper.DiscordAPI.SendMessageAsync(ch, field);
}

public static async Task<string> PrepareBodyMessage(string input, bool forWeb = false)
Expand Down
Loading

0 comments on commit 92002ac

Please sign in to comment.