-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Area command * Enable areas command if EnableCities is false * remove unused config option * change embed color Co-authored-by: Thunder <[email protected]>
- Loading branch information
1 parent
a047916
commit fecdee6
Showing
2 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
using DSharpPlus.CommandsNext; | ||
using DSharpPlus.CommandsNext.Attributes; | ||
using DSharpPlus.Entities; | ||
using DSharpPlus.Interactivity; | ||
|
||
using WhMgr.Diagnostics; | ||
using WhMgr.Extensions; | ||
using WhMgr.Localization; | ||
using WhMgr.Net.Webhooks; | ||
|
||
namespace WhMgr.Commands | ||
{ | ||
public class Areas | ||
{ | ||
private static readonly IEventLogger _logger = EventLogger.GetLogger("AREAS", Program.LogLevel); | ||
|
||
private readonly Dependencies _dep; | ||
|
||
public Areas(Dependencies dep) | ||
{ | ||
_dep = dep; | ||
|
||
} | ||
|
||
[ | ||
Command("areas"), | ||
//Aliases("", ""), | ||
Description("Shows a list of areas") | ||
] | ||
public async Task SendPaginated(CommandContext ctx) | ||
{ | ||
if (!await ctx.IsDirectMessageSupported(_dep.WhConfig)) | ||
return; | ||
|
||
var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); | ||
if (!_dep.WhConfig.Servers.ContainsKey(guildId)) | ||
return; | ||
|
||
var server = _dep.WhConfig.Servers[guildId]; | ||
|
||
var geofences = _dep.Whm.GetServerGeofences(guildId); | ||
|
||
List<string> areas = geofences.Select(geofence => geofence.Name).OrderBy(Name => Name).ToList(); | ||
|
||
|
||
var interactivity = ctx.Client.GetInteractivityModule(); | ||
List<Page> pages = new List<Page>(); | ||
int pagelength = 0; | ||
var psb = new StringBuilder(); | ||
int linesThisPage = 0; | ||
int num = 1; | ||
var title = string.Format("Page {0}", (object)num); | ||
foreach (var line in areas.Select(area => $"- {area}\n")) | ||
{ | ||
var length = line.Length; | ||
var wouldGoOver = length + pagelength > 2000; | ||
|
||
if (wouldGoOver || linesThisPage >= 25) | ||
{ | ||
title = string.Format("Page {0}", (object)num); | ||
var eb = new DiscordEmbedBuilder | ||
{ | ||
Color = DiscordColor.Blue, | ||
Title = title, | ||
Description = psb.ToString(), | ||
}; | ||
pages.Add(new Page { Embed = eb }); | ||
psb.Clear(); | ||
pagelength = 0; | ||
linesThisPage = 0; | ||
++num; | ||
} | ||
|
||
psb.Append(line); | ||
pagelength += length; | ||
linesThisPage++; | ||
} | ||
|
||
if (psb.Length > 0) | ||
{ | ||
title = string.Format("Page {0}", (object)num); | ||
var eb = new DiscordEmbedBuilder | ||
{ | ||
Color = DiscordColor.Red, | ||
Title = title, | ||
Description = psb.ToString(), | ||
|
||
}; | ||
pages.Add(new Page { Embed = eb }); | ||
} | ||
|
||
await interactivity.SendPaginatedMessage(ctx.Channel, ctx.User, pages, timeoutoverride: TimeSpan.FromMinutes(5)); | ||
} | ||
|
||
} | ||
|
||
|
||
} |