Skip to content

Commit

Permalink
Merge pull request #7 from streamyfin/feat/centralizedissue
Browse files Browse the repository at this point in the history
feat: Add message toxicity analysis and enhance piracy keyword detection
  • Loading branch information
sldless authored Jan 31, 2025
2 parents 0eb406c + a2c04fa commit 485861c
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 35 deletions.
56 changes: 40 additions & 16 deletions client.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
const { Client, Collection, EmbedBuilder } = require("discord.js");
const axios = require ("axios");
const axios = require("axios");

module.exports = class Streamyfin extends Client {
constructor(...options) {
super(...options);

this.commands = new Collection();
this.userId = '398161771476549654';
this.repoOrg = process.env.REPO_ORG;
this.repoName = process.env.REPO_NAME;
this.githubToken = process.env.GITHUB_TOKEN;

}
async fetchStats() {

async fetchStats() {
const url = `https://api.github.com/repos/streamyfin/streamyfin/contributors?anon=1`;

const response = await axios.get(url);
const contributors = await response.data;

return contributors.map((contributor) => ({
username: contributor.login || contributor.name,
contributions: contributor.contributions,
username: contributor.login || contributor.name,
contributions: contributor.contributions,
}));
};

async fetchReleases(){
async fetchReleases() {
try {
const response = await axios.get(
`${process.env.GITHUB_API_BASE}/repos/${this.repoOrg}/${this.repoName}/releases`,
Expand All @@ -35,36 +35,60 @@ module.exports = class Streamyfin extends Client {
},
}
);

const releases = response.data
.slice(0, 2) // Fetch the latest 2 releases
.map((release) => ({ name: release.name, value: release.name }));

releases.push({ name: "Older", value: "Older" }); // Add "Older" as an option

return releases;
} catch (error) {
console.error("Error fetching releases:", error);
return [
{ name: "unknown", value: "unknown" }, // Fallback data
{ name: "unknown", value: "unknown" }, // Fallback data
];
}
};

async repoCheck(repoName) {
repoName = repoName.replace(/\s+/g, '-');
repoName = repoName.replace(/\s+/g, '-');
try {
const response = await axios.get(`https://api.github.com/repos/${this.repoOrg}/${repoName}`);
if (response.data && response.data?.id) {
return { exists: true, data: response.data };
return { exists: true, data: response.data };
} else {
return { exists: false };
return { exists: false };
}
} catch (error) {
console.error('Error checking repository:', error.message);
return { exists: false, error: error.message };
}
}

async checkMessage(message) {
try {
const response = await axios.post(
`https://commentanalyzer.googleapis.com/v1alpha1/comments:analyze?key=${process.env.PERSPECTIVE_APIKEY}`,
{
comment: { text: message },
requestedAttributes: { TOXICITY: {}, FLIRTATION: {} },
}
);

if (response.data && response.data.attributeScores) {
const toxicityScore = response.data.attributeScores.TOXICITY.summaryScore.value;
const flirtationScore = response.data.attributeScores.FLIRTATION.summaryScore.value;

return toxicityScore >= 0.2 || flirtationScore >= 0.2;
} else {
throw new Error('Invalid response from Perspective API');
}
} catch (error) {
console.error('Error analyzing message:', error);
return false;
}
}


};
41 changes: 22 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,33 @@ client.on("interactionCreate", async (interaction) => {
})


function pirateList(message) {
function hasPiracyKeywords(message) {
const lowerText = message.toLowerCase();
const list = [
"pirate",
"torrent",
"crack",
"leak",
"P2P",
"illegal content",
"illegal download",
"warez"
];
return list.some((keyword) => lowerText.includes(keyword));
const piracyKeywords = [
"pirate", "torrent", "crack", "crackme", "leak", "p2p", "illegal content",
"illegal download", "downloading", "warez", "camrip", "keygen",
"cracked", "leeching", "magnet link", "ddl", "seed", "tracker", "cyberlocker",
"ripping", "streaming site", "torrent site", "DHT", "soulseek", "fake release",
"subscene", "DMCA takedown"
];
return piracyKeywords.some((keyword) => lowerText.includes(keyword));
}

client.on('messageCreate', message => {
let pirated = pirateList(message.content)
if (pirated) {
let command = client.commands.get("piracy")
command.run(message)
client.on('messageCreate', async (message) => {
const hasPiracy = hasPiracyKeywords(message.content);
console.log(hasPiracy, isToxic)
if (hasPiracy) {
const isToxic = await client.checkMessage(message.content);
if (isToxic) {
const command = client.commands.get("piracy");
if (command) {
command.run(message);
}
}
}
if (message.mentions.has(client.user) && !message.author.bot) {
message.reply("Hi there, I'm Finn! I'm a bot written for streamyfin! To find out what I can do, use `/help`!");
}
message.reply("Hi there, I'm Finn! I'm a bot written for streamyfin! To find out what I can do, use `/help`!");
}
});
const registerCommands = async () => {
if (client.githubToken) await client.fetchReleases();
Expand Down

0 comments on commit 485861c

Please sign in to comment.