Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Pdzly committed Aug 14, 2024
1 parent 8fa06c9 commit ad7c60e
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 35 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dotenv": "^16.3.1",
"express": "^4.18.2",
"http-proxy-middleware": "^2.0.6",
"lemmy-js-client": "^0.18.3-rc.3",
"lemmy-js-client": "^0.19.3-alpha.5",
"mongodb": "^5.8.1",
"move-cli": "^2.0.0",
"node-cron": "^3.0.2",
Expand Down
3 changes: 0 additions & 3 deletions src/commands/logCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export default class LogCommands {
await interaction.deferReply();
try {
const post = await client.getPost({
auth: getAuth(),
id: postId,
});

Expand Down Expand Up @@ -47,7 +46,6 @@ export default class LogCommands {

try {
const post = await client.getPost({
auth: getAuth(),
id: postId,
});

Expand All @@ -74,7 +72,6 @@ export default class LogCommands {
await interaction.deferReply();
try {
const user = await client.getPersonDetails({
auth: getAuth(),
username: userId,
});

Expand Down
2 changes: 1 addition & 1 deletion src/commands/utilCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export default class UtilCommands {
return;
}

const embed = LogHelper.userToEmbed({ person: verifiedUser.lemmyUser });
const embed = LogHelper.userToEmbed({ person: verifiedUser.lemmyUser });

await interaction.editReply({
content: `**Discord:** <@${verifiedUser.discordUser.id}>
Expand Down
2 changes: 0 additions & 2 deletions src/commands/verifyCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ export default class VerifyCommands {
return;
}
const user = await client.getPersonDetails({
auth: getAuth(),
username: username,
});

Expand Down Expand Up @@ -235,7 +234,6 @@ export default class VerifyCommands {
interaction.member as GuildMember
);
client.createPrivateMessage({
auth: getAuth(),
recipient_id: user.person_view.person.id,
content: `Hello ${user.person_view.person.name}!
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/lemmyHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function sleep(ms: number) {
export const instanceUrl = process.env.LEMMY_URL || "https://lemmy.world";

export const isModOfCommunityPersonResponse = async (user: GetPersonDetailsResponse, communityId: number) => {
if(user.person_view.person.admin) return true;
if(user.person_view.is_admin) return true;
try {
const modIds = user.moderates.map((mod) => mod.community.id);
return modIds.includes(communityId);
Expand All @@ -30,8 +30,8 @@ export const isModOfCommunityPersonResponse = async (user: GetPersonDetailsRespo
}
};

export const isModOfCommunityPerson = async (user: Person, communityId: number) => {
if(user.admin) return true;
export const isModOfCommunityPerson = async (user: Person, communityId: number, is_admin: boolean) => {
if(is_admin) return true;
try {
const commService = typeDiDependencyRegistryEngine.getService(CommunityService);
if(!commService) return false;
Expand Down
21 changes: 9 additions & 12 deletions src/helpers/logHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class LogHelper {
iconURL: creator.avatar ? creator.avatar : undefined,
})
.setURL(`${instanceUrl}/comment/${comment.id}`)
.setTimestamp(new Date(counts.published + "Z"))
.setTimestamp(new Date(counts.published))
.setFooter({
text: `Posted in ${community.name}`,
iconURL: community.icon ? `${community.icon}` : undefined,
Expand Down Expand Up @@ -104,7 +104,7 @@ export default class LogHelper {
? post.body.slice(0, 4000) + "..."
: post.body) || "No Body"
)
.setTimestamp(new Date(counts.published + "Z"))
.setTimestamp(new Date(counts.published))
.setFooter({
text: `Posted in ${community.name}`,
iconURL: community.icon ? `${community.icon}` : undefined,
Expand Down Expand Up @@ -171,7 +171,7 @@ export default class LogHelper {
iconURL: creator.avatar ? creator.avatar : undefined,
})
.setDescription(post_report.reason)
.setTimestamp(new Date(post_report.published + "Z"))
.setTimestamp(new Date(post_report.published))
.setFooter({
text: `Reported in ${community.name}`,
iconURL: community.icon ? `${community.icon}` : undefined,
Expand Down Expand Up @@ -204,7 +204,7 @@ export default class LogHelper {
iconURL: creator.avatar ? creator.avatar : undefined,
})
.setDescription(comment_report.reason)
.setTimestamp(new Date(comment_report.published + "Z"))
.setTimestamp(new Date(comment_report.published))
.setFooter({
text: `Reported in ${community.name}`,
iconURL: community.icon ? `${community.icon}` : undefined,
Expand All @@ -216,9 +216,11 @@ export default class LogHelper {
static userToEmbed({
counts,
person,
is_admin,
}: {
counts?: PersonAggregates;
person: Person;
is_admin?: boolean;
}) {
const embed = new EmbedBuilder()
.setTitle("Person Detail")
Expand All @@ -232,10 +234,10 @@ export default class LogHelper {
),
iconURL: person.avatar ? person.avatar : undefined,
})
.setTimestamp(new Date(person.published + "Z"))
.setTimestamp(new Date(person.published))
.addFields([
{ name: "ID", value: String(person.id), inline: true },
{ name: "Admin", value: person.admin ? "Yes" : "No", inline: true },
{ name: "Admin", value: is_admin ? "Yes" : is_admin === undefined ? "Unknown" : "No", inline: true },
])
.setURL(
`${instanceUrl}/u/${
Expand All @@ -255,12 +257,7 @@ export default class LogHelper {
embed.addFields([
{ name: "Posts", value: String(counts.post_count), inline: true },
{ name: "Comments", value: String(counts.comment_count), inline: true },
{
name: "Comment Score",
value: String(counts.comment_score),
inline: true,
},
{ name: "Post Score", value: String(counts.post_score), inline: true },

]);
}

Expand Down
11 changes: 7 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ process.on("uncaughtException", (error) => {
}, 5000);
});


export const extended_guilds: string[] = [
"932286006156222495",
"1128644575276318801"
]
"1128644575276318801",
];

export const bot = new Client({
// To use only guild command
Expand Down Expand Up @@ -89,6 +88,10 @@ async function start() {
username_or_email: process.env.LEMMY_USERNAME || "",
});

client.setHeaders({
Authorization: `Bearer ${results.jwt}`,
});

if (!results.jwt) {
throw new Error("Could not log in to Lemmy");
}
Expand All @@ -107,7 +110,7 @@ async function start() {
} else {
console.log("BOT_TOKEN NOT FOUND. Doesnt starting discord Bot.");
}
startServer()
startServer();

typeDiDependencyRegistryEngine.getService(verifiedUserService);
}
Expand Down
18 changes: 13 additions & 5 deletions src/services/verifiedUserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { Inject, Service } from "typedi";
import "reflect-metadata";
import verifiedUserRepository from "../repository/verifiedUserRepository";
import { BaseGuildTextChannel, Guild, GuildMember, User } from "discord.js";
import { BaseGuildTextChannel, DiscordAPIError, Guild, GuildMember, User } from "discord.js";
import { ObjectId } from "mongodb";
import CommunityService from "./communityService";
import BetterQueue from "better-queue";
Expand Down Expand Up @@ -92,6 +92,7 @@ class verifiedUserService {
}
})
.catch((e) => {
console.log("User not found! " + user.discordUser.id);
console.log(e);
});
await sleep(1000);
Expand All @@ -104,12 +105,20 @@ class verifiedUserService {
`Updated ${user.discordUser.username || user.discordUser.id}`
);
} catch (e) {
if(e instanceof DiscordAPIError){
console.log("Discord API Error");
console.log(e);
if(e.code === 10007){
console.log("Removing user from database");
await this.removeConnection(undefined, undefined, user.discordUser);
}
}
console.log(e);
}
});
cb(null, data);
},
batchDelay: 500,
batchDelay: 500,
batchSize: 2,
afterProcessDelay: 15000,
});
Expand Down Expand Up @@ -379,7 +388,6 @@ class verifiedUserService {
id: communityId,
});
return (
connection.lemmyUser.admin ||
(community &&
community.moderators.some(
(m) => m.moderator.id === connection.lemmyUser.id
Expand All @@ -406,8 +414,8 @@ class verifiedUserService {
person.person_view.person.id +
(Math.random() * 100) / 100 +
Math.random() *
(person.person_view.counts.post_score +
person.person_view.counts.comment_score +
(person.person_view.counts.post_count +
person.person_view.counts.comment_count +
Math.random() * 100)
);
this.codes.push({
Expand Down

0 comments on commit ad7c60e

Please sign in to comment.