Skip to content

Commit

Permalink
Create "Free" role config option (#111)
Browse files Browse the repository at this point in the history
* Create "Free" role config option

* Update config.example.json
  • Loading branch information
versx authored Dec 28, 2020
1 parent 209fe9d commit 693b2a9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 44 deletions.
2 changes: 2 additions & 0 deletions config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"emojiGuildId": 000000000000000001,
"ownerId": 000000000000000000,
"donorRoleIds": [],
"freeRoleName": "",
"moderatorRoleIds": [],
"token": "<DISCORD_BOT_TOKEN>",
"alarms": "alarms.json",
Expand Down Expand Up @@ -96,6 +97,7 @@
"emojiGuildId": 000000000000000001,
"ownerId": 000000000000000000,
"donorRoleIds": [],
"freeRoleName": "",
"moderatorRoleIds": [],
"token": "<DISCORD_BOT_TOKEN>",
"alarms": "alarms2.json",
Expand Down
45 changes: 10 additions & 35 deletions src/Commands/Feeds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ public async Task FeedMeAsync(CommandContext ctx,
return;

var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x));

var isSupporter = await ctx.Client.IsSupporterOrHigher(ctx.User.Id, guildId, _dep.WhConfig);
if (!_dep.WhConfig.Servers.ContainsKey(guildId))
return;

var server = _dep.WhConfig.Servers[guildId];
if (server.CitiesRequireSupporterRole && !isSupporter)
var isSupporter = await ctx.Client.IsSupporterOrHigher(ctx.User.Id, guildId, _dep.WhConfig);
var isFreeRole = string.IsNullOrEmpty(server.FreeRoleName) ? false : string.Compare(cityName, server.FreeRoleName, true) == 0;
if (server.CitiesRequireSupporterRole && !isSupporter && !isFreeRole)
{
await ctx.DonateUnlockFeaturesMessage();
return;
Expand All @@ -105,7 +105,7 @@ public async Task FeedMeAsync(CommandContext ctx,
var cityRoles = server.CityRoles.Select(x => x.ToLower());
foreach (var city in cityNames)
{
if (!cityRoles.Contains(city.ToLower()))
if (!isFreeRole && !cityRoles.Contains(city.ToLower()))
{
await ctx.RespondEmbed(Translator.Instance.Translate("FEEDS_INVALID_CITY_NAME_TYPE_COMMAND").FormatText(ctx.User.Username, city, server.CommandPrefix), DiscordColor.Red);
continue;
Expand All @@ -128,20 +128,6 @@ public async Task FeedMeAsync(CommandContext ctx,
alreadyAssigned.Add(cityRole.Name);
}

var cityRaidRole = ctx.Guild.GetRoleFromName($"{city}Raids");
if (cityRaidRole != null)
{
result = await AddFeedRole(ctx.Member, cityRaidRole);
if (result)
{
assigned.Add(cityRaidRole.Name);
}
else
{
alreadyAssigned.Add(cityRaidRole.Name);
}
}

Thread.Sleep(200);
}

Expand Down Expand Up @@ -178,9 +164,13 @@ public async Task FeedMeNotAsync(CommandContext ctx,
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 isSupporter = await ctx.Client.IsSupporterOrHigher(ctx.User.Id, guildId, _dep.WhConfig);
if (_dep.WhConfig.Servers[guildId].CitiesRequireSupporterRole && !isSupporter)
var isFreeRole = string.IsNullOrEmpty(server.FreeRoleName) ? false : string.Compare(cityName, server.FreeRoleName, true) == 0;
if (server.CitiesRequireSupporterRole && !isSupporter && !isFreeRole)
{
await ctx.DonateUnlockFeaturesMessage();
return;
Expand All @@ -193,17 +183,15 @@ public async Task FeedMeNotAsync(CommandContext ctx,
return;
}

var server = _dep.WhConfig.Servers[guildId];
var unassigned = new List<string>();
var alreadyUnassigned = new List<string>();

try
{
var cityNames = cityName.RemoveSpaces();
var cityRoles = server.CityRoles;
foreach (var city in cityNames)
{
if (!cityRoles.Exists(x => string.Compare(city, x, true) == 0))
if (!isFreeRole && !server.CityRoles.Exists(x => string.Compare(city, x, true) == 0))
{
await ctx.RespondEmbed(Translator.Instance.Translate("FEEDS_INVALID_CITY_NAME_TYPE_COMMAND").FormatText(ctx.User.Username, city, server.CommandPrefix), DiscordColor.Red);
continue;
Expand All @@ -225,19 +213,6 @@ public async Task FeedMeNotAsync(CommandContext ctx,
alreadyUnassigned.Add(cityRole.Name);
}

var cityRaidRole = ctx.Guild.GetRoleFromName($"{city}Raids");
if (cityRaidRole == null)
continue;

if (await RemoveFeedRole(ctx.Member, cityRaidRole))
{
unassigned.Add(cityRaidRole.Name);
}
else
{
alreadyUnassigned.Add(cityRaidRole.Name);
}

Thread.Sleep(200);
}

Expand Down
10 changes: 1 addition & 9 deletions src/Commands/Notifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ public async Task PokeMeAsync(CommandContext ctx,
// If so, make sure they specified at least 90% or higher
if (realIV < 90)
{
await ctx.TriggerTypingAsync();
await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_MINIMUM_IV").FormatText(ctx.User.Username), DiscordColor.Red);
return;
}
Expand Down Expand Up @@ -388,7 +387,6 @@ public async Task PokeMeAsync(CommandContext ctx,
{
if (!MasterFile.Instance.Pokedex.ContainsKey(pokemonId))
{
await ctx.TriggerTypingAsync();
await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_POKEMON_ID").FormatText(ctx.User.Username, pokemonId), DiscordColor.Red);
continue;
}
Expand All @@ -399,7 +397,6 @@ public async Task PokeMeAsync(CommandContext ctx,
// Check if common type pokemon e.g. Pidgey, Ratatta, Spinarak 'they are beneath him and he refuses to discuss them further'
if (pokemonId.IsCommonPokemon() && realIV < Strings.CommonTypeMinimumIV && !isModOrHigher)
{
await ctx.TriggerTypingAsync();
await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_COMMON_TYPE_POKEMON").FormatText(ctx.User.Username, pokemon.Name, Strings.CommonTypeMinimumIV), DiscordColor.Red);
continue;
}
Expand Down Expand Up @@ -1248,14 +1245,12 @@ public async Task PvpMeAsync(CommandContext ctx,
//You may only subscribe to the top 100 or higher rank.
if (minimumRank < Strings.MinimumRank || minimumRank > Strings.MaximumRank)
{
await ctx.TriggerTypingAsync();
await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_PVP_RANK_RANGE").FormatText(ctx.User.Username, minimumRank), DiscordColor.Red);
return;
}

if (minimumPercent < Strings.MinimumPercent || minimumPercent > Strings.MaximumPercent)
{
await ctx.TriggerTypingAsync();
await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_PVP_RANK_RANGE").FormatText(ctx.User.Username, minimumPercent), DiscordColor.Red);
return;
}
Expand Down Expand Up @@ -1283,7 +1278,6 @@ public async Task PvpMeAsync(CommandContext ctx,
{
if (!MasterFile.Instance.Pokedex.ContainsKey(pokemonId))
{
await ctx.TriggerTypingAsync();
await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_POKEMON_ID").FormatText(ctx.User.Username, pokemonId), DiscordColor.Red);
continue;
}
Expand Down Expand Up @@ -1381,7 +1375,6 @@ public async Task PvpMeNotAsync(CommandContext ctx,
var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id);
if (subscription == null || subscription?.PvP?.Count == 0)
{
await ctx.TriggerTypingAsync();
await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_NO_POKEMON_SUBSCRIPTIONS").FormatText(ctx.User.Username), DiscordColor.Red);
return;
}
Expand Down Expand Up @@ -1411,7 +1404,6 @@ public async Task PvpMeNotAsync(CommandContext ctx,
.ToList()?
.ForEach(x => x.Id.Remove<PvPSubscription>());

await ctx.TriggerTypingAsync();
await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_SUCCESS_REMOVE_ALL_PVP_SUBSCRIPTIONS").FormatText(ctx.User.Username, pvpLeague));
_dep.SubscriptionProcessor.Manager.ReloadSubscriptions();
return;
Expand Down Expand Up @@ -2603,7 +2595,7 @@ public async Task ImportAsync(CommandContext ctx)
var oldSubscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id);
if (oldSubscription != null)
{
var result = Data.Subscriptions.SubscriptionManager.RemoveAllUserSubscriptions(guildId, ctx.User.Id);
var result = SubscriptionManager.RemoveAllUserSubscriptions(guildId, ctx.User.Id);
if (!result)
{
_logger.Error($"Failed to clear old user subscriptions for {ctx.User.Username} ({ctx.User.Id}) in guild {ctx.Guild?.Name} ({ctx.Guild?.Id}) before importing.");
Expand Down
3 changes: 3 additions & 0 deletions src/Configuration/DiscordServerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public class DiscordServerConfig
[JsonProperty("donorRoleIds")]
public List<ulong> DonorRoleIds { get; set; }

[JsonProperty("freeRoleName")]
public string FreeRoleName { get; set; }

/// <summary>
/// Gets or sets the moderators of the Discord server
/// </summary>
Expand Down

0 comments on commit 693b2a9

Please sign in to comment.