Skip to content

Commit 900875d

Browse files
committed
Úprava skriptu a oprava chyby, kdy bot nenakupoval, pokud byl špatně nastaven Telegram bot.
1 parent 741b605 commit 900875d

File tree

3 files changed

+80
-62
lines changed

3 files changed

+80
-62
lines changed

CryptoBotCore/BotStrategies/AccumulationBot.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class AccumulationBot
2424
[NonSerialized]
2525
private Dictionary<string, CoinmateAPI> coinmateAPIs;
2626

27-
TelegramBotClient bot = new TelegramBotClient(BotConfiguration.TelegramBot);
27+
TelegramBotClient TelegramBot { get; set; }
2828

2929
private CosmosDbContext _cosmosDbContext;
3030

@@ -207,7 +207,8 @@ public async Task<string> SendMessageAsync(string message, MessageTypeEnum messa
207207

208208
try
209209
{
210-
await bot.SendTextMessageAsync(BotConfiguration.TelegramChannel, message, Telegram.Bot.Types.Enums.ParseMode.Html);
210+
TelegramBot = new TelegramBotClient(BotConfiguration.TelegramBot);
211+
await TelegramBot.SendTextMessageAsync(BotConfiguration.TelegramChannel, message, Telegram.Bot.Types.Enums.ParseMode.Html);
211212
}
212213
catch (Exception e)
213214
{

CryptoBotFunction/install_script.ps1

Lines changed: 75 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ $WithdrawalEnabled='false'
2727
$WithdrawalAddress=''
2828

2929
# (Využije se pouze v případě, kdy $WithdrawalEnabled='true').
30-
# Maximální limit v procentech, kdy dovolujete botovi zaslat naakumulované krypto do své peněženky
30+
# Maximální limit na withdrawal fee v procentech. (DEFAULT: 0.001 = 0.1 %)
3131
$MaxWithdrawalPercentageFee = '0.001'
3232

3333
# (Využije se pouze v případě, kdy $WithdrawalEnabled='true').
34-
# Maximální limit v absolutní hodnotě (Kč), kdy dovolujete botovi zaslat naakumulované krypto do své peněženky
34+
# Maximální limit na withdrawal fee v absolutní hodnotě (Kč)
3535
# Pokud je nastaveno -1, uplatní se pouze podmínka procentuální => $MaxWithdrawalPercentageFee
3636
$MaxWithdrawalAbsoluteFee = -1
3737

@@ -50,8 +50,6 @@ $CoinMateCredentials_PublicKey='XXX'
5050
# Private key z Coinmate API
5151
$CoinMateCredentials_PrivateKey='XXX'
5252

53-
##############################
54-
5553
########################
5654
### SYSTEM VARIABLES ###
5755
########################
@@ -101,6 +99,7 @@ if (0 -eq $LoginResult.Count){
10199
exit
102100
}
103101

102+
Write-Host "Login to Azure was successful. Please wait, installation will take several minutes..." -ForegroundColor cyan
104103

105104
################ RESOURCE GROUP #####################
106105

@@ -117,6 +116,19 @@ if ( $existingResourceGroups.Count -gt 0 )
117116
az group create -l $location -n $resourceGroupName
118117
}
119118

119+
# Resource group check
120+
$query = "[?name == '" + $resourceGroupName + "']"
121+
$existingEntity = az group list --query $query | ConvertFrom-Json
122+
123+
if ( $existingEntity.Count -eq 0 )
124+
{
125+
$err = "ERROR: Resource group check failed."
126+
throw $err
127+
exit
128+
}
129+
130+
Write-Host "[Step 1 / 8] Resource group -> DONE" -ForegroundColor cyan
131+
120132
################ COSMOSDB ACCOUNT #####################
121133

122134
#Kontrola, zdali již náhodou CosmosDB v rámci Resource group "AccBot" neexistuje
@@ -131,11 +143,31 @@ if ( $existingEntity.Count -gt 0 )
131143

132144
$alreadyExistPrint = "CosmosDB account '" + $cosmosDBAccountName + "' already exists. This step will be skipped."
133145
Write-Warning $alreadyExistPrint
146+
147+
Write-Host "[Step 2 / 8] CosmosDB account -> DONE" -ForegroundColor cyan
148+
Write-Host "[Step 3 / 8] CosmosDB DB -> DONE" -ForegroundColor cyan
149+
Write-Host "[Step 4 / 8] CosmosDB DB Container -> DONE" -ForegroundColor cyan
134150
}else{
135151
#Vytvoření CosmosDB
136152
$CosmosDBAccountResult = az cosmosdb create -n $cosmosDBAccountName -g $resourceGroupName --only-show-errors --default-consistency-level Session | ConvertFrom-Json
153+
154+
# CosmosDB account check
155+
$query = "[?contains(name, 'accbotcosmosdbaccount') && resourceGroup == '" + $resourceGroupName + "']"
156+
$existingEntity = az cosmosdb list --query $query | ConvertFrom-Json
157+
158+
if ( $existingEntity.Count -eq 0 )
159+
{
160+
$err = "ERROR: CosmosDB account check failed."
161+
throw $err
162+
exit
163+
}
164+
Write-Host "[Step 2 / 8] CosmosDB account -> DONE" -ForegroundColor cyan
165+
166+
137167
$cosmosDbResult = az cosmosdb sql database create --account-name $cosmosDBAccountName --resource-group $resourceGroupName --only-show-errors --name $cosmosDBName | ConvertFrom-Json
168+
Write-Host "[Step 3 / 8] CosmosDB DB -> DONE" -ForegroundColor cyan
138169
$containerResult = az cosmosdb sql container create -g $resourceGroupName -a $cosmosDBAccountName -d $cosmosDBName -n $cosmosContainerName --only-show-errors --partition-key-path "/CryptoName" --throughput "400" | ConvertFrom-Json
170+
Write-Host "[Step 4 / 8] CosmosDB DB Container -> DONE" -ForegroundColor cyan
139171
}
140172

141173

@@ -180,6 +212,19 @@ if ( $existingEntity.Count -gt 0 )
180212
az storage account create -n $storageAccountName -g $resourceGroupName --only-show-errors --sku Standard_LRS
181213
}
182214

215+
# Azure storage account check
216+
$query = "[?contains(name, 'accbotsa') && resourceGroup == '" + $resourceGroupName + "']"
217+
$existingEntity = az storage account list --query $query | ConvertFrom-Json
218+
219+
if ( $existingEntity.Count -eq 0 )
220+
{
221+
$err = "ERROR: Azure storage account check failed."
222+
throw $err
223+
exit
224+
}
225+
226+
Write-Host "[Step 5 / 8] Storage account -> DONE" -ForegroundColor cyan
227+
183228
########################################################### AZURE FUNCTIONAPP ############################################################
184229

185230
#Kontrola, zdali již náhodou Azure functionapp v rámci resource group AccBot neexistuje
@@ -199,8 +244,21 @@ if ( $existingEntity.Count -gt 0 )
199244
az functionapp create -g $resourceGroupName -n $azFunctionName -s $storageAccountName --only-show-errors --functions-version 3 --consumption-plan-location $location
200245
}
201246

247+
# Azure functionapp check
248+
$query = "[?contains(name, 'accbotfunction') && resourceGroup == '" + $resourceGroupName + "']"
249+
$existingEntity = az functionapp list --query $query | ConvertFrom-Json
250+
251+
if ( $existingEntity.Count -eq 0 )
252+
{
253+
$err = "ERROR: Azure functionapp check failed."
254+
throw $err
255+
exit
256+
}
257+
258+
Write-Host "[Step 6 / 8] Function app -> DONE" -ForegroundColor cyan
259+
202260
#Nastavení proměnných
203-
az functionapp config appsettings set --name $azFunctionName --resource-group $resourceGroupName `
261+
$appsettingsResult = az functionapp config appsettings set --name $azFunctionName --resource-group $resourceGroupName `
204262
--settings "Name=$Name" `
205263
"Currency=$Currency" `
206264
"Fiat=$Fiat" `
@@ -218,56 +276,6 @@ az functionapp config appsettings set --name $azFunctionName --resource-group $r
218276
"CoinMateCredentials_PublicKey=$CoinMateCredentials_PublicKey" `
219277
"CoinMateCredentials_PrivateKey=$CoinMateCredentials_PrivateKey"
220278

221-
222-
#Deploy AccBota do Azure function
223-
$env:SCM_DO_BUILD_DURING_DEPLOYMENT='true'
224-
$DeployAzureFunctionResult = az functionapp deployment source config-zip -g $resourceGroupName -n $azFunctionName --src $zipDeploymentFileName --only-show-errors
225-
226-
################################################### Závěrečná kontrola skriptu ############################################################
227-
# Resource group check
228-
$query = "[?name == '" + $resourceGroupName + "']"
229-
$existingEntity = az group list --query $query | ConvertFrom-Json
230-
231-
if ( $existingEntity.Count -eq 0 )
232-
{
233-
$err = "ERROR: Resource group check failed."
234-
throw $err
235-
exit
236-
}
237-
238-
# CosmosDB account check
239-
$query = "[?contains(name, 'accbotcosmosdbaccount') && resourceGroup == '" + $resourceGroupName + "']"
240-
$existingEntity = az cosmosdb list --query $query | ConvertFrom-Json
241-
242-
if ( $existingEntity.Count -eq 0 )
243-
{
244-
$err = "ERROR: CosmosDB account check failed."
245-
throw $err
246-
exit
247-
}
248-
249-
# Azure storage account check
250-
$query = "[?contains(name, 'accbotsa') && resourceGroup == '" + $resourceGroupName + "']"
251-
$existingEntity = az storage account list --query $query | ConvertFrom-Json
252-
253-
if ( $existingEntity.Count -eq 0 )
254-
{
255-
$err = "ERROR: Azure storage account check failed."
256-
throw $err
257-
exit
258-
}
259-
260-
# Azure functionapp check
261-
$query = "[?contains(name, 'accbotfunction') && resourceGroup == '" + $resourceGroupName + "']"
262-
$existingEntity = az functionapp list --query $query | ConvertFrom-Json
263-
264-
if ( $existingEntity.Count -eq 0 )
265-
{
266-
$err = "ERROR: Azure functionapp check failed."
267-
throw $err
268-
exit
269-
}
270-
271279
# Azure functionapp settings check
272280
$query = "[?contains(name, 'CosmosDbPrimaryKey')]"
273281
$existingEntity = az functionapp config appsettings list --query $query -g $resourceGroupName -n $azFunctionName | ConvertFrom-Json
@@ -279,20 +287,29 @@ if ( $existingEntity.Count -eq 0 )
279287
exit
280288
}
281289

290+
Write-Host "[Step 7 / 8] Function app settings uploading -> DONE" -ForegroundColor cyan
291+
292+
293+
#Deploy AccBota do Azure function
294+
$env:SCM_DO_BUILD_DURING_DEPLOYMENT='true'
295+
$DeployAzureFunctionResult = az functionapp deployment source config-zip -g $resourceGroupName -n $azFunctionName --src $zipDeploymentFileName --only-show-errors
296+
297+
# Azure functionapp deployment check
282298
if( $null -eq $DeployAzureFunctionResult ){
283299
$err = "ERROR: Azure function deployment failed."
284300
throw $err
285301
exit
286302
}
287303

304+
Write-Host "[Step 8 / 8] Function app deployment -> DONE" -ForegroundColor cyan
305+
288306

289307
#Zobrazit výstup co se stalo
290-
$output = "Úspěšně se vytvořily následující entity v Azure: `n`t ResourceGroup: " + $resourceGroupName + "`n"`
308+
$output = "The following entities were successfully created in Azure: `n`t ResourceGroup: " + $resourceGroupName + "`n"`
291309
+ "`t CosmosDBAccount: " + $cosmosDBAccountName + "`n"`
292310
+ "`t Azure storage: " + $storageAccountName + "`n"`
293311
+ "`t Azure function: " + $azFunctionName + "`n"`
294-
+ " => Bot je již nasazen a nyní by měl začít nakupovat " + $Currency + " v " + $randomMinutes + ". minutu každou " + $NextHour + "hodinu."
312+
+ " => The AccBot bot is already deployed and should now start buying " + $Currency + " at " + $randomMinutes + ". minute every " + $NextHour + "hour."
295313

296314
Write-Host $output -ForegroundColor green
297-
298315
pause

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ $WithdrawalEnabled='false'
6262
$WithdrawalAddress=''
6363
6464
# (Využije se pouze v případě, kdy $WithdrawalEnabled='true').
65-
# Maximální limit v procentech, kdy dovolujete botovi zaslat naakumulované krypto do své peněženky
65+
# Maximální limit na withdrawal fee v procentech. (DEFAULT: 0.001 = 0.1 %)
6666
$MaxWithdrawalPercentageFee = '0.001'
6767
6868
# (Využije se pouze v případě, kdy $WithdrawalEnabled='true').
69-
# Maximální limit v absolutní hodnotě (Kč), kdy dovolujete botovi zaslat naakumulované krypto do své peněženky
69+
# Maximální limit na withdrawal fee v absolutní hodnotě (Kč)
7070
# Pokud je nastaveno -1, uplatní se pouze podmínka procentuální => $MaxWithdrawalPercentageFee
7171
$MaxWithdrawalAbsoluteFee = -1
7272

0 commit comments

Comments
 (0)