Removing old Legacy code

This commit is contained in:
Sean "Solao Bajiuik" Stoves 2020-08-05 19:30:33 -04:00
parent 16dec32abc
commit 965a7faebd
3 changed files with 0 additions and 252 deletions

View File

@ -1,39 +0,0 @@
using System;
using Discord;
using Discord.Commands;
using System.Threading.Tasks;
using System.Collections.Generic;
using ChaosBot.Discord.PreConditions;
using NLog;
namespace ChaosBot.Discord.Modules
{
public class AdminCommands : ModuleBase
{
private static readonly ILogger _logger = Program.Logger;
[Command("clear")]
[Alias("purge")]
[RequireBotPermission(GuildPermission.ManageMessages)]
[RequireUserPermission(GuildPermission.ManageMessages)]
[CheckCommandPerm]
public async Task ClearCommand(int msgtoDelete = 1)
{
try
{
IEnumerable<IMessage> messages = await Context.Channel.GetMessagesAsync(msgtoDelete + 1).FlattenAsync();
await ((ITextChannel) Context.Channel).DeleteMessagesAsync(messages);
const int delay = 3000;
IUserMessage m = await ReplyAsync($"{msgtoDelete} messages deleted.");
await Task.Delay(delay);
await m.DeleteAsync();
}
catch (Exception ex)
{
_logger.Error($"AdminCommands.ClearCommand: Exception [{ex}] thrown, <[{ex.Message}]>.");
}
}
}
}

View File

@ -1,91 +0,0 @@
using System;
using System.Linq;
using Discord;
using Discord.Commands;
using System.Threading.Tasks;
using NLog;
using System.Text;
using System.Text.Json;
using ChaosBot.Discord.PreConditions;
using ChaosBot.Models;
using ChaosBot.Repositories;
namespace ChaosBot.Discord.Modules
{
public class ConfigCommands : ModuleBase
{
private static readonly ILogger _logger = Program.Logger;
[Command("config")]
[CheckCommandPerm]
public async Task setConfig(string configFlag = null, string value = null)
{
var sb = new StringBuilder();
var embed = new EmbedBuilder();
try
{
if (configFlag == null || value == null)
{
string prefix = ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!");
await ReplyAsync($"Syntax Wrong. Please see {prefix}config help");
return;
}
using (ChaosbotContext dbContext = new ChaosbotContext())
{
Configuration config = dbContext.Configuration
.FirstOrDefault(c => c.DiscordGuildId == Context.Guild.Id && c.Key == configFlag);
// TODO: Is this warning valid?
config.SerializedValue = JsonSerializer.Serialize(value);
dbContext.SaveChanges();
}
embed.WithColor(new Color(255, 255, 0));
embed.Title = $"Configuration Management";
sb.AppendLine($"{Context.User.Mention} has changed the Configuration.");
sb.AppendLine();
sb.AppendLine($"{configFlag} == {value}");
/*
* Add the string to the Embed
*/
embed.Description = sb.ToString();
/*
* Reply with the Embed created above
*/
await ReplyAsync(null, false, embed.Build());
}
catch (Exception ex)
{
_logger.Error($"ConfigCommands.setCfg: Exception [{ex}] thrown, <[{ex.Message}]>.");
}
}
[Command("config help")]
[RequireBotPermission(GuildPermission.ManageGuild)]
[RequireUserPermission(GuildPermission.ManageGuild)]
public async Task helpConfig(string configFlag = null, string value = null)
{
string prefix = ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!");
var sb = new StringBuilder();
var embed = new EmbedBuilder();
embed.WithColor(new Color(255, 255, 0));
embed.Title = $"Configuration Management Help";
sb.AppendLine();
sb.AppendLine($"{prefix}config <configFlag> <value>");
/*
* Add the string to the Embed
*/
embed.Description = sb.ToString();
/*
* Reply with the Embed created above
*/
await ReplyAsync(null, false, embed.Build());
}
}
}

View File

@ -1,122 +0,0 @@
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dice;
using Discord;
using Discord.Commands;
using Microsoft.VisualBasic;
using NLog;
namespace ChaosBot.Discord.Modules
{
public class DiceCommands : ModuleBase
{
private static ILogger _logger = Program.Logger;
[Command("roll")]
public async Task Roll(params string[] args)
{
string diceRecipe = Strings.Join(args, " ");
try
{
var sb = new StringBuilder();
var embed = new EmbedBuilder();
RollResult rollResult = Roller.Roll(diceRecipe);
embed.WithColor(new Color(255, 255,0));
// embed.Title = $"Dice Roll";
sb.AppendLine($"{Context.User.Mention} :game_die:");
sb.AppendLine($"Result: {diceRecipe} ({DiceOutput(rollResult)})");
sb.AppendLine($"Total: {rollResult.Value}");
/*
* Add the string to the Embed
*/
embed.Description = sb.ToString();
/*
* Reply with the Embed created above
*/
await ReplyAsync(null, false, embed.Build());
}
catch (Exception ex)
{
_logger.Error($"DiceCommands.Roll: Exception [{ex}] thrown, <[{ex.Message}]>.");
}
}
private string DiceOutput(RollResult rollResult)
{
if (rollResult.RollRoot == null) return "";
StringBuilder sb = new StringBuilder();
foreach (DieResult dieResult in rollResult.RollRoot.Values)
{
string result = ParseDiceResult(dieResult);
sb.Append(DieFormatting(dieResult.Flags));
sb.Append(result);
sb.Append(DieFormatting(dieResult.Flags, true));
}
return sb.ToString();
}
private string ParseDiceResult(DieResult dieResult)
{
switch (dieResult.DieType)
{
case DieType.Normal:
case DieType.Literal:
return dieResult.Value.ToString();
case DieType.Special:
switch (dieResult.SpecialDie)
{
case SpecialDie.Add:
return "+";
case SpecialDie.Comma:
return ",";
case SpecialDie.Divide:
return "/";
case SpecialDie.Multiply:
return "*";
case SpecialDie.Negate:
return "~";
case SpecialDie.Subtract:
return "-";
case SpecialDie.Text:
return dieResult.Data;
case SpecialDie.CloseParen:
return ")";
case SpecialDie.OpenParen:
return "(";
}
break;
}
return "";
}
private string DieFormatting(DieFlags flags, bool reverse=false)
{
StringBuilder sb = new StringBuilder();
if ((flags & (DieFlags.Critical ^ DieFlags.Success ^ DieFlags.Failure ^ DieFlags.Fumble)) != 0)
sb.Append("**");
if ((flags & DieFlags.Dropped) != 0)
sb.Append("~~");
if ((flags & DieFlags.Extra) != 0)
sb.Append("*");
if (reverse)
return new string(sb.ToString().Reverse().ToArray());
return sb.ToString();
}
}
}