Skip to content

Commit

Permalink
Merge pull request #163 from ca45382/develop
Browse files Browse the repository at this point in the history
v1.0.1用
  • Loading branch information
ca45382 authored Feb 21, 2023
2 parents d88fdd2 + d03e2dc commit d4bec64
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 58 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ bld/
[Ll]og/
[Ll]ogs/

Properties/Resources.Designer.cs

# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
Expand Down
6 changes: 3 additions & 3 deletions ShioriBot.sln
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31105.61
# Visual Studio Version 17
VisualStudioVersion = 17.0.31919.166
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShioriBot.Net", "src/ShioriBot.Net.csproj", "{24C95780-F93B-425D-9B2A-6D1B941FC8A7}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShioriBotDotNet", "src\ShioriBotDotNet.csproj", "{24C95780-F93B-425D-9B2A-6D1B941FC8A7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
22 changes: 0 additions & 22 deletions src/Extension/EnumerableExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,5 @@ public static void ForEach<T>([NotNull] this IEnumerable<T> source, [NotNull] Ac
action(element);
}
}

public static TSource MaxBy<TSource, TValue>([NotNull] this IEnumerable<TSource> source, [NotNull] Func<TSource, TValue> func)
where TValue : IComparable<TValue>
{
var firstFlag = true;
TValue maxValue = default;
TSource maxSource = default;

foreach (var element in source)
{
var value = func(element);

if (firstFlag || value.CompareTo(maxValue) > 0)
{
maxValue = value;
maxSource = element;
firstFlag = false;
}
}

return maxSource;
}
}
}
4 changes: 2 additions & 2 deletions src/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Script/ClanBattle/BattleDeclaration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private async Task SendDeclarationBotMessage()
var embed = CreateDeclarationDataEmbed();
var content = CreateDeclarationDataMessage();
var component = CreateDeclareComponent();
var sentMessage = await m_DeclarationChannel.SendMessageAsync(text: content, embed: embed, component: component);
var sentMessage = await m_DeclarationChannel.SendMessageAsync(text: content, embed: embed, components: component);

if (sentMessage == null)
{
Expand Down
8 changes: 7 additions & 1 deletion src/Script/ClanBattle/BattleReservationSummary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public async Task SendMessage()
{
var embedData = CreateEmbed();
var componentData = CreateComponent();
var sendedMessageData = await m_SocketTextChannel.SendMessageAsync(embed: embedData, component: componentData);
var sendedMessageData = await m_SocketTextChannel.SendMessageAsync(embed: embedData, components: componentData);
DatabaseMessageDataController.UpdateMessageID(m_ClanData, sendedMessageData.Id, MessageFeatureType.ReserveResultID);
}

Expand All @@ -67,6 +67,12 @@ public async Task UpdateMessage()
}

var reservationMessageID = m_ClanData.GetMessageID(MessageFeatureType.ReserveResultID);

if (reservationMessageID == 0)
{
return;
}

var cachedMessage = m_SocketTextChannel.GetCachedMessage(reservationMessageID);
var embedData = CreateEmbed();
var componentData = CreateComponent();
Expand Down
26 changes: 18 additions & 8 deletions src/Script/ClanBattle/UpdateDate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public async Task DeleteYesterdayData()
sw.Start();

var nowTime = DateTime.Now;
//var nowTime = new DateTime(2022, 3, 28, 6,0,0);

var reservarionDataList = DatabaseReservationController.LoadReservationData()
.Where(x => x.CreateDateTime < m_BoundaryTime);
Expand All @@ -55,20 +56,29 @@ public async Task DeleteYesterdayData()
continue;
}

taskList.Add(new BattleTaskKill(clanRole).SyncTaskKillData());

if (RediveClanBattleData.ClanBattleStartTime <= nowTime && nowTime <= RediveClanBattleData.ClanBattleEndTime)
try
{
taskList.Add(new BattleReservationSummary(clanRole).UpdateMessage());
taskList.Add(new BattleTaskKill(clanRole).SyncTaskKillData());

for (int i = 0; i < CommonDefine.MaxBossNumber; i++)
if (RediveClanBattleData.ClanBattleStartTime <= nowTime && nowTime <= RediveClanBattleData.ClanBattleEndTime)
{
taskList.Add(new BattleDeclaration(clanRole, (BossNumberType)(i + 1)).UpdateDeclarationBotMessage());
// TODO:ここに進行の方も追加
taskList.Add(new BattleReservationSummary(clanRole).UpdateMessage());

for (int i = 0; i < CommonDefine.MaxBossNumber; i++)
{
taskList.Add(new BattleDeclaration(clanRole, (BossNumberType)(i + 1)).UpdateDeclarationBotMessage());
// TODO:ここに進行の方も追加
}
}

await Task.WhenAll(taskList);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}

await Task.WhenAll(taskList);
await Task.Delay(1000);
}

sw.Stop();
Expand Down
30 changes: 14 additions & 16 deletions src/Script/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public async Task MainAsync()

m_client = new DiscordSocketClient(m_config);
m_client.MessageReceived += CommandRecieved;
m_client.GuildMembersDownloaded += GuildMembersDownloaded;
m_client.UserLeft += UserLeft;
m_client.Ready += Client_Ready;
m_client.GuildMemberUpdated += GuildMemberUpdated;
m_client.InteractionCreated += InteractionCreated;
m_client.Log += Log;
Expand Down Expand Up @@ -91,22 +90,20 @@ private async Task CommandRecieved(SocketMessage socketMessage)
/// </summary>
/// <param name="guild"></param>
/// <returns></returns>
private Task GuildMembersDownloaded(SocketGuild guild)
private async Task Client_Ready()
{
var discordDataLoader = new DiscordDataLoader();
discordDataLoader.UpdateServerData(guild);
discordDataLoader.UpdateClanData(guild);
discordDataLoader.UpdatePlayerData(guild);
return Task.CompletedTask;
}
var guildList = m_client.Guilds;

private Task UserLeft(SocketGuildUser userInfo)
{
var discordDataLoader = new DiscordDataLoader();
discordDataLoader.UpdateServerData(userInfo.Guild);
discordDataLoader.UpdateClanData(userInfo.Guild);
discordDataLoader.UpdatePlayerData(userInfo.Guild);
return Task.CompletedTask;
await Task.Run(() =>
{
foreach (var guild in guildList)
{
var discordDataLoader = new DiscordDataLoader();
discordDataLoader.UpdateServerData(guild);
discordDataLoader.UpdateClanData(guild);
discordDataLoader.UpdatePlayerData(guild);
}
});
}

private Task GuildMemberUpdated(Cacheable<SocketGuildUser, ulong> cachedGuildUser, SocketGuildUser newUserInfo)
Expand All @@ -126,6 +123,7 @@ private async Task InteractionCreated(SocketInteraction socketInteraction)
}

await new ReceiveInteractionController(socketInteraction).Run();
await socketInteraction.DeferAsync();
}

private async Task RefreshInUpdateDate()
Expand Down
6 changes: 5 additions & 1 deletion src/Script/Utility/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ public static class Logger
public static async Task SendLogMessage(SocketRole role, ClanData clanData, string logMessage)
{
var logChannel = role.Guild.GetTextChannel(clanData.GetChannelID(ChannelFeatureType.LogID));
await logChannel.SendMessageAsync(logMessage);

if (logChannel != null)
{
await logChannel.SendMessageAsync(logMessage);
}
}
}
}
11 changes: 7 additions & 4 deletions src/ShioriBot.Net.csproj → src/ShioriBotDotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Configurations>Debug;Release</Configurations>
<RootNamespace>ShioriBot</RootNamespace>
<AssemblyName>ShioriBotDotNet</AssemblyName>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Discord.Net.Labs" Version="3.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.11" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="5.0.2" />
<PackageReference Include="Discord.Net" Version="3.9.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.14" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.2" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit d4bec64

Please sign in to comment.