Fixed backup file names, improved handling of renaming things
This commit is contained in:
parent
42d169f157
commit
dd01dba88d
|
@ -55,18 +55,20 @@ namespace DeukBot4.MessageHandlers
|
|||
{
|
||||
using (var client = new WebClient())
|
||||
{
|
||||
var attachmentSplit = attachment.Filename.Split('.');
|
||||
var filename = $"{attachmentSplit[0]}-{DateTime.UtcNow:s}.{attachmentSplit[1]}";
|
||||
|
||||
var content = client.DownloadData(attachment.Url);
|
||||
var uri = new Uri($"{Settings.URL}/{attachment.Filename}-{DateTime.UtcNow:s}");
|
||||
var uri = new Uri($"{Settings.URL}/{filename}");
|
||||
client.Credentials = new NetworkCredential(Settings.Username, Settings.Password);
|
||||
try
|
||||
{
|
||||
client.UploadData(uri, "PUT", content);
|
||||
var attachmentSplit = attachment.Filename.Split('.');
|
||||
var eb = new EmbedBuilder()
|
||||
{
|
||||
Title = "Image Backed Up",
|
||||
Description = $"Image with the name ``{attachment.Filename}`` was backed up as " +
|
||||
$"``{attachmentSplit[0]}-{DateTime.UtcNow:s}.{attachmentSplit[1]}``",
|
||||
$"``{filename}``",
|
||||
ThumbnailUrl = attachment.Url,
|
||||
Timestamp = DateTime.UtcNow
|
||||
};
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using DeukBot4.Utilities;
|
||||
using Discord.WebSocket;
|
||||
|
||||
namespace DeukBot4.MessageHandlers
|
||||
|
@ -37,10 +38,10 @@ namespace DeukBot4.MessageHandlers
|
|||
|
||||
private static async Task DeltaHandler(SocketMessage message)
|
||||
{
|
||||
var lower = message.Content.ToLowerInvariant().Split(' ');
|
||||
var lower = message.Content.ToLowerInvariant().RemoveSpecialCharacters().Split(' ');
|
||||
foreach (var s in lower)
|
||||
{
|
||||
var diff = Utilities.Lehvenstein.LevenshteinDistance(s, "delta");
|
||||
var diff = Lehvenstein.LevenshteinDistance(s, "delta");
|
||||
if (diff <= 1)
|
||||
{
|
||||
await message.Channel.SendMessageAsync("uhh excuse me it's called Origin and it's an art");
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
using System.Text;
|
||||
|
||||
namespace DeukBot4.Utilities
|
||||
{
|
||||
public static class StringExtensions
|
||||
{
|
||||
public static string RemoveSpecialCharacters(this string str) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (char c in str) {
|
||||
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) {
|
||||
sb.Append(c);
|
||||
}
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue