Skip to content
This repository has been archived by the owner on Jan 23, 2019. It is now read-only.

Commit

Permalink
Fixed #1. Implemented animated emoji support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Emzi0767 committed Dec 22, 2017
1 parent d5fc1a7 commit 71b87a7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
13 changes: 6 additions & 7 deletions EmoteScavenger/Emoji.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
using System;

namespace EmoteScavenger
namespace EmoteScavenger
{
public struct Emoji
{
public string Name { get; }
public ulong Id { get; }
public string GuildName { get; }
public ulong GuildId { get; }
public string Url { get; }
public bool IsAnimated { get; }

public Emoji(string name, ulong id, string guildName, ulong guildId)
public Emoji(string name, ulong id, string guildName, ulong guildId, string url, bool anim)
{
this.Name = name;
this.Id = id;
this.GuildName = guildName;
this.GuildId = guildId;
this.Url = url;
this.IsAnimated = anim;
}

public Uri GetUri()
=> new Uri($"https://cdn.discordapp.com/emojis/{this.Id}.png");
}
}
5 changes: 4 additions & 1 deletion EmoteScavenger/EmoteScavenger.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<LangVersion>7.1</LangVersion>

<Version>1.0.1</Version>
<FileVersion>$(Version).0</FileVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DSharpPlus" Version="4.0.0-beta-00397" />
<PackageReference Include="DSharpPlus" Version="4.0.0-beta-00399" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.0.1" />
</ItemGroup>

Expand Down
5 changes: 3 additions & 2 deletions EmoteScavenger/MultiDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public Task DownloadAllAsync(IEnumerable<Emoji> emojis)
foreach (var emoji in emojis)
{
var td = dirs[emoji.GuildId];
var tf = Path.Combine(td.FullName, $"{emoji.Name}.png");
var tf = Path.Combine(td.FullName, $"{emoji.Name}");
tf = string.Concat(tf, emoji.IsAnimated ? ".gif" : ".png");

tasks.Add(DownloadAsync(emoji, new FileInfo(tf)));
}
Expand All @@ -64,7 +65,7 @@ private async Task DownloadAsync(Emoji emoji, FileInfo targetFile)

try
{
using (var res = await this.Http.GetAsync(string.Format(SOURCE_URL, emoji.Id)))
using (var res = await this.Http.GetAsync(emoji.Url))
using (var str = await res.Content.ReadAsStreamAsync())
using (var fs = targetFile.Create())
await str.CopyToAsync(fs);
Expand Down
2 changes: 1 addition & 1 deletion EmoteScavenger/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private static FileInfo GetTokenLocation()
private static string ExtractToken(FileInfo dbf)
{
var tfn = string.Concat(dbf.FullName, ".tmp");
dbf = dbf.CopyTo(tfn);
dbf = dbf.CopyTo(tfn, true);

string token = null;
using (var db = new StorageContext(dbf))
Expand Down
2 changes: 1 addition & 1 deletion EmoteScavenger/Scavenger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private Task Discord_GuildAvailable(GuildCreateEventArgs e)

var xg = e.Guild;
foreach (var xe in xg.Emojis)
this.Emojis.Add(new Emoji(xe.Name, xe.Id, xg.Name, xg.Id));
this.Emojis.Add(new Emoji(xe.Name, xe.Id, xg.Name, xg.Id, xe.Url, xe.IsAnimated));

if (this.GuildsToSync.TryDequeue(out var gld))
return e.Client.SyncGuildsAsync(gld);
Expand Down

0 comments on commit 71b87a7

Please sign in to comment.