Skip to content

Commit

Permalink
chore: use storage octokit
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Oct 4, 2024
1 parent 54ee0d1 commit d57398f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/compute.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ jobs:
env:
TELEGRAM_BOT_ENV: ${{ secrets.TELEGRAM_BOT_ENV }}
STORAGE_APP_ID: ${{ secrets.STORAGE_APP_ID }}
STORAGE_APP_PRIVATE_KEY: ${{ secrets.STORAGE_APP_PRIVATE_KEY }}
STORAGE_APP_PRIVATE_KEY: ${{ secrets.STORAGE_APP_PRIVATE_KEY }}
1 change: 0 additions & 1 deletion src/adapters/github/storage-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export class GithubStorage {
* This way we'll be able to build a single storage location
* for partners, we'll be able to access data directly from
* a Telegram payload as otherwise we'd need a PAT.
*
*/
async getStorageOctokit() {
if (this.isEnvSetup) {
Expand Down
57 changes: 28 additions & 29 deletions src/bot/features/commands/private-chat/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,42 @@ const feature = composer.chatType("private");
* Pairs the user's Telegram ID with the user's GitHub ID.
*/
feature.command("register", logHandle("command-register"), chatAction("typing"), async (ctx) => {
const userId = ctx.from?.id;
const githubUsername = ctx.message?.text?.split(" ")[1];
const parts = [];
try {
const userId = ctx.from?.id;
const githubUsername = ctx.message?.text?.split(" ")[1];

if (!githubUsername) {
await ctx.reply("Please provide your GitHub username like this: /register <GitHubUsername>");
return;
}
if (!githubUsername) {
await ctx.reply("Please provide your GitHub username like this: /register <GitHubUsername>");
return;
}

const octokit = ctx.adapters.github.octokit;
const user = await octokit.rest.users.getByUsername({ username: githubUsername });
const storageOctokit = await ctx.adapters.github.getStorageOctokit();
const user = await storageOctokit.rest.users.getByUsername({ username: githubUsername });

if (user.status !== 200) {
await ctx.reply("User not found.");
return;
}
if (user.status !== 200) {
await ctx.reply("User not found.");
return;
}

const githubId = user.data.id;
const githubId = user.data.id;

const parts = [];

if (user.data.login) {
parts.push(`<b>Login:</b> ${user.data.login}`);
}
if (user.data.login) {
parts.push(`<b>Login:</b> ${user.data.login}`);
}

if (user.data.name) {
parts.push(`<b>Name:</b> ${user.data.name}`);
}
if (user.data.name) {
parts.push(`<b>Name:</b> ${user.data.name}`);
}

if (user.data.email) {
parts.push(`<b>Email:</b> ${user.data.email}`);
}
if (user.data.email) {
parts.push(`<b>Email:</b> ${user.data.email}`);
}

if (user.data.bio) {
parts.push(`<b>Bio:</b> ${user.data.bio}`);
}
if (user.data.bio) {
parts.push(`<b>Bio:</b> ${user.data.bio}`);
}

try {
await ctx.adapters.github.handleUserBaseStorage(
{
additionalUserListeners: [],
Expand All @@ -61,7 +60,7 @@ feature.command("register", logHandle("command-register"), chatAction("typing"),
);
} catch (er) {
if (er instanceof Error) {
await ctx.reply(ctx.logger.error(`${er.message}`, { er, userId, githubId }).logMessage.raw);
await ctx.reply(ctx.logger.error(`${er.message}`, { er }).logMessage.raw);
return;
}
await ctx.reply("An error occurred while trying to register your account.");
Expand Down
1 change: 0 additions & 1 deletion src/bot/features/commands/private-chat/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ feature.command("wallet", logHandle("command-wallet"), chatAction("typing"), asy
const userId = ctx.from?.id;
const walletAddress = ctx.message?.text?.split(" ")[1];
try {

if (!walletAddress || walletAddress.trim().length !== 42) {
await ctx.reply("Please provide a valid wallet address like this: /wallet 0x...");
return;
Expand Down
6 changes: 3 additions & 3 deletions src/bot/helpers/grammy-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ export function createContextConstructor({ logger, config }: Dependencies) {
/**
* We'll need to add handling to detect forks and in such cases
* we'll need to handle the storage differently.
*
*
* Storing the repository full name would work, and we already have it
* during setup. Otherwise via plugin config.
*
*
* if (me.username !== "ubiquity_os_bot") { }
*/

/**
* We only operate as one organization on telegram, so I'm assuming
* We only operate as one organization on telegram, so I'm assuming
* that we'll be centralizing the storage obtained.
*/
this.adapters = createAdapters(ctx, "ubq-testing");
Expand Down

0 comments on commit d57398f

Please sign in to comment.